2014-01-21 10 views
5

Können Sie sagen, wie ich alle Cookies in private System.Windows.Forms.WebBrowser webBrowser1 löschen kann. Ich benutzteLöschen Sie Cookies in WebBrowser ohne Neustart

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

Ich möchte dies mit einem Klick auf die Schaltfläche tun.

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

Aber es funktioniert nicht. Und ich weiß über 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());}}}})())"); Es ist nicht für mich geeignet.

+0

Dies kann funktionieren, aber es ist undokumentiert: http://StackOverflow.com/q/17369275/1768303. Je nach Ihren Zielen kann dies auch hilfreich sein: http://stackoverflow.com/a/21254020/1768303. – Noseratio

+1

Ich verstehe nicht ganz, wo ich dynamische 'document = webBrowser.Document; document.execommand ("ClearAuthenticationCache", false); 'In meinem Button ?? Ich bekomme Microsoft.CSharp.RuntimeBinder.RuntimeBinderException in System.Core.dll – jenius

+1

System.Windows.Forms.HtmlDocument enthält keine Definition für "execCommand" – jenius

Antwort

5

die korrekte Eingabe ist wie folgt:

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

Beifall.

+3

Funktioniert nicht mit .Net 4.5 und Facebook Login Flow. –