How to clear WebBrowser cache in WPF application?

三世轮回 提交于 2020-08-07 04:22:07

问题


I am using the WebBrowser control to display a Login page for user to signing to their account and then application will get contacts from that account.

However, the problem is if user select option "Keep signing" from browser, browser will cache that account name and next login with different account, it will return previous cached account name. This lead to application will get wrong account name.

You guys know how to force WebBrowser to clear all cache before proceed to prevent this problem?

I think WebBrowser use Internet Explorer, which is version 11 on my machine.


回答1:


I solved my problem by follow this link: http://mdb-blog.blogspot.com/2013/02/c-winforms-webbrowser-clear-all-cookies.html




回答2:


The browser is keeping the login information in a cookie. Just clear the cookies on exit, or whenever you find suitable:

webBrowser.Navigate("javascript:void((function(){var a,b,c,e,f;f=0;a=document.cookie.split('; ');for(e=0;e<    a.length&&a[e];e++){f++;for(b='.'+location.host;b;b=b.replace(/^(?:%5C.|[^%5C.]+)/,'')){for(    c=location.pathname;c;c=c.replace(/.$/,'')){document.cookie=(a[e]+'; domain='+b+'; path='+c+'; expires='+new Date((    new Date()).getTime()-1e11).toGMTString());}}}})())")

(snippet taken from: How to delete Cookies from windows.form?)



来源:https://stackoverflow.com/questions/37806321/how-to-clear-webbrowser-cache-in-wpf-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!