6

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.

Thong Vo
  • 809
  • 1
  • 9
  • 21
  • web browser uses IE settings. you need to change your IE to settings clear cache upon exit. – Dr. Stitch Jun 14 '16 at 08:06
  • @Dr.Stitch So if I move my application to another machine, I will have to resetting IE on that machine? – Thong Vo Jun 14 '16 at 08:09
  • Seems like you're trying to fix the wrong problem, or not explaining it well enough. At the moment, it sounds like "the user decided to exercise their prerogative to use a particular option. I (through my program) know better than the user and in retaliation, I'm going to wipe out a whole load of their settings" – Damien_The_Unbeliever Jun 14 '16 at 08:09
  • @Damien_The_Unbeliever Sorry if information not clear. My application is design to display a WebBrowser for user to log in with many account, so that it can get contacts from these account. So the option "Keep me signing" will not approriate here because not everyone would like to get contact from the same account everytime. – Thong Vo Jun 14 '16 at 08:13
  • yes, IE settings will affect your Web Browser control settings. – Dr. Stitch Jun 14 '16 at 08:14
  • @Dr.Stitch This would be not practical because it will affect IE on normal use. Anyway thanks for your help. – Thong Vo Jun 14 '16 at 08:15

2 Answers2

3

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

Thong Vo
  • 809
  • 1
  • 9
  • 21
0

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?)

Community
  • 1
  • 1
omerts
  • 8,485
  • 2
  • 32
  • 39
  • This won't pick up [HTTP only cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies) which are inaccessible from JavaScript – Day Nov 19 '17 at 14:54
  • @Day, correct, though I highly doubt these are the type of cookies the issue has. – omerts Nov 19 '17 at 16:23