dsi*_*dsi 3 c# vb.net internet-explorer webbrowser-control browser-cache
在我的应用程序中,用户将通过单击菜单来打开多个选项卡。每个选项卡都是动态创建的,并包含用于加载URL的Web浏览器控件。
每个URL指向同一台服务器,因此某些URL没有访问权限,从而Resource not have access收到错误。
现在,问题就出在例子中-如果用户直接单击Menu3并加载了带有Web浏览器URL的相关选项卡,然后继续下一步,则URL包含其他弹出链接,则它可以工作并且能够弹出URL。
现在,用户单击Menu5无法访问的位置,从而得到此错误Resource not have access(从服务器). Its fine.
NOw, again URL reach toMenu3 and try to open sub link to popup dialog then it gives403禁止的错误拒绝访问中被拒绝。它最初起作用,但后来却给出了该错误。
看起来,我需要清除WebBrowser Control缓存或强制从新会话开始。
谁能指导我如何强制WebBrowser开始新的会话或删除较早的缓存?
WebBrowser 控件的缓存与 Internet Explorer 相同。您有多种选择:
1) 完全清除缓存(也将清除 Internet Explorer!):
2)在服务器响应中使用一些标签:
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
Run Code Online (Sandbox Code Playgroud)
3)使用随机查询字符串强制刷新:
WebBrowser1.Navigate('http://www.example.com/?refresh=' & Guid.NewGuid().ToString())
Run Code Online (Sandbox Code Playgroud)
4) 强制刷新页面(这将加载页面 2 次!):
WebBrowser1.Navigate('http://www.example.com/')
WebBrowser1.Refresh(WebBrowserRefreshOption.Completely)
Run Code Online (Sandbox Code Playgroud)
小智 5
有更好的选择。它使用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);
Run Code Online (Sandbox Code Playgroud)
这将结束浏览器的会话缓存。调用此方法后,Web浏览器控件将忘记内存中的所有会话