I have been googling for hours and trying to figure this out, and I just can't. I have 1 webbrowser control on a form, webbrowser1.
Once I load a page, say google.com, if I use webbrowser1.refresh()
or webbrowser1.navigate("google.com")
, it's not reloading the page, it has it cached so it's just reloading the cache. This is terribly apparent especially on pages like forums or craigslist.
I need to clear the cache between each refresh (not ideal) or disable caching all together, any ideas? The only things I've found are outdated (vb6 or lower).
You can't disable it. You can either refresh the page, clear the cache before each request, or use something other than the web browser control. If you want to clear the cache before each request, there is a LOT of bad information online. I would recommend you to my answer here: https://stackoverflow.com/a/22074463/1607218. Beware, the code posted in the other answers on that page is NOT reliable, and is massively buggy, but hopefully my answer will lead you in the right direction : )
You could try to call
webbrowser1.Refresh(WebBrowserRefreshOption.Completely)
. It should refresh the page and show the latest version, something like ctrl+F5 in IE. See here and here more info.This page shows how to clear some temp file, read it. I also have this issue, but when .refresh() is not useful to me as it doesnt trigger documentcomplete event. So when I wish to reload, I simply use
.navigate()
and before navigation I call thein order to clear cache.
In the .navigate method, you pass the number 2 (the no history flag) but this will only kill history for that navigation, won't kill history for when you follow links. If you want to kill history for links that are clicked on, then you can intercept navigation during beforenavigate event, cancel the navigation by setting cancel = true and then using the URL provided by the event, re doing the navigation using .navigate with the flag set to 2 again (the no history flag).
As far as other cache items like cookies, the flags don't work (though they may have implemented this in current versions)... Soto kill all cache items you actually need to programmatically do this outside of the web browser control by querying user cache using other Apis and deleting it, perhaps during document complete event or when browsing is done.
Also be aware that if you kill history using web browser control, the web browser controls .goback method will not work (as it uses the same history unfortunately, and doesn't keep another history list in memory)... So when doing a goback, it will act like there was nothing to go back to :/.
Let me know if you need more help.
Add following meta tag in your pages
C# WebBrowser control: Clearing cache without clearing cookies