【发布时间】:2014-02-11 11:49:05
【问题描述】:
你能说我如何删除private System.Windows.Forms.WebBrowser webBrowser1 中的所有cookie。我用过
[DllImport("wininet.dll", SetLastError = true)]
private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
我想通过点击按钮来做到这一点。
private void button1_Click(object sender, EventArgs e)
{
InternetSetOption(IntPtr.Zero, INTERNET_OPTION_END_BROWSER_SESSION, IntPtr.Zero, 0);
}
但它不起作用。我知道
webBrowser1.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());}}}})())");
不适合我。
【问题讨论】:
-
这可能有效,但没有记录:stackoverflow.com/q/17369275/1768303。这也可能会有所帮助,具体取决于您的目标:stackoverflow.com/a/21254020/1768303。
-
我不太明白应该将动态
document=webBroweser.Document; document.execCommand("ClearAuthenticationCache", false);放在我的按钮中的什么位置??我在 System.Core.dll 中得到 Microsoft.CSharp.RuntimeBinder.RuntimeBinderException -
System.Windows.Forms.HtmlDocument 不包含“execCommand”的定义
-
您忘记了
dynamic关键字:dynamic document=webBroweser.Document;。没有hard-typedexecCommand方法,除非你使用MSHTML PIA。 -
我只在这条评论中忘记了。
标签: c# cookies browser webbrowser-control