Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In my application, user will open multiple tabs by clicking on menus. Each tab is dynamically created and containing webbrowser control to load URL.

Each URL point to same server and some of URL does not have access so , gives Resource not have access error received.

Now, problem is, example- If user directly click on Menu3 and related tab loaded with webbrowser URL and follow to next, URL contain other popup link then it works and able to popup the URL.

Now, user click on Menu5 where 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.

As it looks, I need to clear the WebBrowser Control cache or forcely start with new session.

Can any one please guide me how to force WebBrowser to start new session or remove earlier caches ?

like image 615
dsi Avatar asked Dec 20 '22 02:12

dsi


2 Answers

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

like image 65
JAnton Avatar answered Dec 28 '22 08:12

JAnton


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)
like image 27
JohnKiller Avatar answered Dec 28 '22 08:12

JohnKiller