ada
ada

Reputation: 63

Windows Phone 7 clear cookies

Is there any possibility to clear cookies generated by WebBrowser control in Silverlight on Windows Phone 7?

Upvotes: 4

Views: 4045

Answers (4)

Jeff Wilcox
Jeff Wilcox

Reputation: 6385

Another solution that I came across was actually to immediately log out the user after the initial OAuth2 handshake.

So once I have their final OAuth2 token, I quickly navigate to the logout page, allowing the cookies to be mostly cleared at that time.

Upvotes: 0

Yiannis
Yiannis

Reputation: 880

I read this in a blog post yesterday but I can't find the link now. In short: 1.Create an HttpWebRequest to the server. 2.Attach a cookie collection to it. 3.Keep a reference to this HttpWebRequest throughout your application's lifetime. 4.The cookies of the WebBrowser control will always be reflected in that HttpWebRequest's CookieCollection. When you want to delete them, iterate though that CookieCollection and mark each one of them as Expired.

I am not sure that the above will work, but you can always try.

Upvotes: 0

Matt Lacey
Matt Lacey

Reputation: 65586

According to this post, cookies cannot be accessed via the API. They can however, be accessed via javascript in an embedded browser (remember to set .IsScriptEnabled = true).

To loop through all cookies and deleted thme you could try something like:

var cookies = document.cookie.split(";"); 
for (var i = 0; i < cookies.length; i++) {
    eraseCookies(cookies[i].split("=")[0]);
} 

Or, if eraseCookies doens't work (I haven't checked) you could try:

createCookie(cookies[i].split("=")[0], "", -1);

Upvotes: 0

Related Questions