您能说出如何删除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());}}}})())");
它不适合我。
答案 0 :(得分:5)
正确的输入如下:
dynamic document = webBrowser1.Document;
document.ExecCommand("ClearAuthenticationCache", false, null);
干杯。