views:

157

answers:

2

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

A: 

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);
Matt Lacey
Does this JavaScript code delete all cookies or cookies only from certain domain?
ada
pass. Have to try it and see.
Matt Lacey
A: 

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.

Papajohn