问题
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