Delete cookies in webBrowser without restart

心不动则不痛 提交于 2019-12-06 03:40:11

问题


Can you say how I can delete all cookies in private System.Windows.Forms.WebBrowser webBrowser1. I used

[DllImport("wininet.dll", SetLastError = true)]
private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);

I want do this with button click.

private void button1_Click(object sender, EventArgs e)
{
         InternetSetOption(IntPtr.Zero, INTERNET_OPTION_END_BROWSER_SESSION, IntPtr.Zero, 0);
} 

But it doesn't work. And I know about 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());}}}})())"); It isn't suitable for me.


回答1:


the correct typing is as follows:

dynamic document = webBrowser1.Document;
document.ExecCommand("ClearAuthenticationCache", false, null);

Cheers.



来源:https://stackoverflow.com/questions/21265674/delete-cookies-in-webbrowser-without-restart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!