且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何清除System.Windows.Forms.WebBrowser会话数据?

更新时间:2023-02-08 17:48:28

要清除会话(如仅Http饼干),你可以使用的wininet.dll InternetSetOption()。

To clear session (such as HttpOnly cookies), you can use InternetSetOption() from wininet.dll.

private const int INTERNET_OPTION_END_BROWSER_SESSION = 42;

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

和使用这种方法时需要明确的会话。

and use this method whenever need to clear session.

InternetSetOption(IntPtr.Zero, INTERNET_OPTION_END_BROWSER_SESSION, IntPtr.Zero, 0);
webBrowser1.Document.Window.Navigate(url);