Is there any possibility to clear cookies开发者_Python百科 generated by WebBrowser control in Silverlight on Windows Phone 7?
http://cloudstore.blogspot.com/2010/09/clearing-cookies-on-windows-phone-7-or.html
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);
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.
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.
精彩评论