vb.net 如何强制 WebBrowser Control 使用新会话或清除会话
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31050047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Force WebBrowser Control to use New Session or clear sessions
提问by dsi
In my application, user will open multiple tabs by clicking on menus. Each tab is dynamically created and containing webbrowser controlto load URL.
在我的应用程序中,用户将通过单击菜单打开多个选项卡。每个选项卡都是动态创建的,并包含用于加载 URL 的webbrowser 控件。
Each URL point to same server and some of URL does not have access so , gives Resource not have accesserror received.
每个 URL 都指向同一个服务器,并且某些 URL 无法访问,因此会Resource not have access收到错误消息。
Now, problem is, example- If user directly click on Menu3and related tab loaded with webbrowser URL and follow to next, URL contain other popup link then it works and able to popup the URL.
现在,问题是,例如 - 如果用户直接单击Menu3加载了网络浏览器 URL 的相关选项卡并跟随下一步,URL 包含其他弹出链接,则它可以工作并能够弹出 URL。
Now, user click on Menu5where not have access so, get this error Resource not have access(denied from server). Its fine.
NOw, again URL reach toMenu3and try to open sub link to popup dialog then it gives403 forbidden error- decline access`. It works initially but, later it just giving this error.
现在,用户点击Menu5没有访问权限的地方,得到这个错误Resource not have access(拒绝来自服务器). Its fine.
NOw, again URL reach toMenu3 and try to open sub link to popup dialog then it gives403 禁止错误-拒绝访问`。它最初有效,但后来它只是给出了这个错误。
As it looks, I need to clear the WebBrowser Controlcache or forcely start with new session.
看起来,我需要清除WebBrowser Control缓存或强制启动新会话。
Can any one please guide me how to force WebBrowserto start new session or remove earlier caches ?
任何人都可以指导我如何强制WebBrowser启动新会话或删除较早的缓存吗?
回答by JohnKiller
The cache of the WebBrowser control is the same of Internet Explorer. You have various options:
WebBrowser 控件的缓存与 Internet Explorer 相同。您有多种选择:
1) Completely clear that cache (will also clear Internet Explorer!):
1) 完全清除缓存(也将清除 Internet Explorer!):
https://stackoverflow.com/a/24401521/2633161
https://stackoverflow.com/a/24401521/2633161
2) Use some tags in the server response:
2)在服务器响应中使用一些标签:
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
3) Use a random query string to force the refresh:
3)使用随机查询字符串强制刷新:
WebBrowser1.Navigate('http://www.example.com/?refresh=' & Guid.NewGuid().ToString())
4) Force refresh of the page (this will load the page 2 times!):
4) 强制刷新页面(这将加载页面 2 次!):
WebBrowser1.Navigate('http://www.example.com/')
WebBrowser1.Refresh(WebBrowserRefreshOption.Completely)
回答by JAnton
There is a better alternative. It's using the WinINet.DLL and calling SetInternetOptions
有一个更好的选择。它使用 WinINet.DLL 并调用 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
这将结束浏览器的会话缓存。调用此方法后,webbrowser 控件将忘记内存中的任何会话

