How to Force WebBrowser Control to use New Session or clear sessions

三世轮回 提交于 2019-12-04 14:29:52

There is a better alternative. It's using the WinINet.DLL and calling SetInternetOptions

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

    private const int INTERNET_OPTION_END_BROWSER_SESSION = 42;

InternetSetOption(IntPtr.Zero, INTERNET_OPTION_END_BROWSER_SESSION, IntPtr.Zero, 0);

This will end the browser's session cache. After you call this method the webbrowser control will forget whatever sessions had in memory

JohnKiller

The cache of the WebBrowser control is the same of Internet Explorer. You have various options:

1) Completely clear that cache (will also clear Internet Explorer!):

https://stackoverflow.com/a/24401521/2633161

2) Use some tags in the server response:

<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">

3) Use a random query string to force the refresh:

WebBrowser1.Navigate('http://www.example.com/?refresh=' & Guid.NewGuid().ToString())

4) Force refresh of the page (this will load the page 2 times!):

WebBrowser1.Navigate('http://www.example.com/')
WebBrowser1.Refresh(WebBrowserRefreshOption.Completely)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!