【发布时间】:2012-11-04 15:42:40
【问题描述】:
我正在使用WebBrowser 控件编写Windows 窗体应用程序,我需要在Web 服务器上更改Session ID。我该怎么做?有什么方法可以重启或重新打开浏览器吗?
【问题讨论】:
标签: c# winforms webbrowser-control sessionid
我正在使用WebBrowser 控件编写Windows 窗体应用程序,我需要在Web 服务器上更改Session ID。我该怎么做?有什么方法可以重启或重新打开浏览器吗?
【问题讨论】:
标签: c# winforms webbrowser-control sessionid
要清除会话(例如 HttpOnly cookie),您可以使用 wininet.dll 中的 InternetSetOption()。
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);
并在需要清除会话时使用此方法。
InternetSetOption(IntPtr.Zero, INTERNET_OPTION_END_BROWSER_SESSION, IntPtr.Zero, 0);
webBrowser1.Document.Window.Navigate(url);
【讨论】: