Welcome Guest Search | Active Topics | Sign In | Register

WebBrowser CookieCollection Options
Michael George
Posted: Thursday, May 15, 2014 11:20:53 AM
Rank: Newbie
Groups: Member

Joined: 5/14/2014
Posts: 8
I am new to the WebBrowser control which I am using within a VB.Net Winforms application. I noticed in the documentation there is a class named CookieCollection which seems that it would allow you to access the cookies associated with the WebBrowser control however I cannot figure out how to access it.

Can anyone shed some light? Perhaps with a snippet of VB.net code?

Thank you,

Michael George
eo_support
Posted: Thursday, May 15, 2014 12:34:53 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

That class is primarily for you to works with cookies associated to a Request object, it is not for you to access the cookies associated with a WebControl/WebView. A WebView contain maintain many cookies, but since most cookies are associated to a Url, when a Request is sent, only those cookies that matches the Request's Url will appear in the Request's Cookies collection.

For example, if you log in both Google and Yahoo's website with a WebView, then the WebView will have two authentication cookies: one for Google and one for Yahoo. Now if you access a page on Yahoo's website, the BeforeRequestLoad event will be triggered. The event argument of this event will give you a Request object, through whose Cookies collection you will see all the cookies that the WebView has picked to send with this Request to yahoo's server. In this Request's Cookies collection, you will see the authentication cookie for Yahoo (and maybe other cookies that Yahoo previously sent to this WebView too), but you will not see Google's authentication cookie for this particular request.

While you handle BeforeRequestLoad event, you can also modify the Cookies collection by adding your own additional cookies to the request. When you do that, your additional cookies will be sent to the server as well. You can also delete cookies from the collection but it is not recommended for you to do that as obviously that can mess up the page logic. For example, if you choose to clear the Cookies collection every time, then the server might just always send you back to the login page since it expects an authentication cookies that was never sent to the server.

Hope this helps. Please feel free to let us know if you have any more questions.

Thanks!
Michael George
Posted: Thursday, May 15, 2014 1:32:15 PM
Rank: Newbie
Groups: Member

Joined: 5/14/2014
Posts: 8
The BeforeRequestLoad event was the bit I was missing.

Thank you,

Michael George
eo_support
Posted: Thursday, May 15, 2014 2:06:44 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Great. Glad to hear that you found what you were looking for.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.