Clearing "session state" of WebBrowser control

B

BobRoyAce

I have a form that cycles through a bunch of websites, some of them
multiple times in a row. For each one, it opens up a second form, with
a WebBrowser control on it, and navigates to the website, and
automates loggin in, navigating around, etc. This works just great.
However, for one of the websites, it would appear that some sort of
"session state" is being remembered as when I go to login as another
person, to this same site, I end up at a page that corresponds with
the first person I logged in as.

NOTE 1: I close the form with the WebBrowser control on it each time.

NOTE 2: It doesn't always happen (i.e. inconsistent).

NOTE 3: This error does not seem to happen if I do the same navigation
manually, using IE browser outside of my application, closing the
browser each time.

So, I guess that my question is "How do I clear the 'session state' so
that next time the form is opened, etc., it is not present to goof up
the next login?"

I tried the following code, that I partly got from
http://stackoverflow.com/questions/434469/how-to-clear-system-windows-forms-webbrowser-session-data,
which did not work:

WebBrowser1.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());}}}})())")

Any other ideas why I might be having the problem, and how I can fix
it?
 
J

John Bundy

This could be caused by a few things, not only are their cookies, but I have
run into sites that actually store a file out in a temp directory that has to
be erased. Depending on the site, what works for me the most often is adding
a ? and a digit to the end of the URL. This is typically passed straight
through as it usually contains parameters for a page or query, and it does
seem to open a new page every time. Cant guarantee it will work for you in
this situation, but it has worked for me everytime i have used it. I just add
? and i have a function that apends a random 7 digit number onto the end.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top