How to disable caching in the .NET WebBrowser Control?

后端 未结 8 1738
我寻月下人不归
我寻月下人不归 2021-01-04 20:01

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.

相关标签:
8条回答
  • 2021-01-04 20:14

    use navigate(url,4) 0x4=noCache flag

    0 讨论(0)
  • 2021-01-04 20:24

    Add following meta tag in your pages

    <meta http-equiv="cache-control" content="no-cache">
    
    0 讨论(0)
  • 2021-01-04 20:25

    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.

    0 讨论(0)
  • 2021-01-04 20:28

    C# WebBrowser control: Clearing cache without clearing cookies

    0 讨论(0)
  • 2021-01-04 20:30

    You could try adding a random number or guid in the url as a parameter. Such as:

    var url = "http://google.com";
    webBrowser.Navigate(url + "?refreshToken=" + Guid.NewGuid().ToString());
    

    It's not elegant, but it works. Hope it helps.

    0 讨论(0)
  • 2021-01-04 20:36

    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 the

    System.Diagnostics.Process.Start("rundll32.exe","InetCpl.cpl,ClearMyTracksByProcess 8")
    

    in order to clear cache.

    0 讨论(0)
提交回复
热议问题