如何从windows.form删除cookies? [英] How to delete Cookies from windows.form?

查看:128
本文介绍了如何从windows.form删除cookies?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对C#编写一个应用程序windows.form WebBrowser控件的工作。我想编写一个方法从Webbrowers控制删除的cookie它访问某个网站之后。不幸的是,我不知道如何做到这些,并没有发现在互联网上有很多的帮助。

I am working with the Webbrowser control on a windows.form application written in C#. I would like to write a method for deleting the cookies from the Webbrowers control after it visits a certain site. Unfortunately, I don't know how to do that exactly and haven't found a lot of help on the internet.

如果任何人有经验,其实这样做,不只是假设,因为它可能是棘手比现在看来,我不知道。

If anyone has experience actually doing this, not just hypothetical because it might be trickier than it seems, I don't know.

int count = webBrowser2.Document.Cookie.Length;
webBrowser2.Document.Cookie.Remove(0,count);

我只是假设像上述code会工作,但我想不会。任何人都可以提供一些线索在这整个饼干的事情吗?

I would just assume something like the above code would work but I guess it won't. Can anyone shed some light on this whole cookie thing?

推荐答案

如果您启用JavaScript你可以使用这个code段清除清除Cookie在网站上的网页浏览器是目前

If you have JavaScript enabled you can just use this code snippet to clear to clear the cookies for the site the webbrowser is currently on.

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

这是一个从得出这个书签清理饼干。

这篇关于如何从windows.form删除cookies?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆