How to force HttpWebRequest to use cache in ASP.NET environment?

前端 未结 3 2001
庸人自扰
庸人自扰 2021-02-09 09:33

In my ASP.NET app I use HttpWebRequest for fetching external resources which I\'d like to be cached. Consider the following code:

var req = WebRequest.Create(\"h         


        
相关标签:
3条回答
  • 2021-02-09 09:55

    You can use the cache manually in your code like this:

     Cache.Insert("request", req, Nothing, DateTime.Now, TimeSpan.FromSeconds(30), TimeSpan.Zero)
    

    You can use this Method like you would use caching with in web.config.

    0 讨论(0)
  • 2021-02-09 10:03

    I know this is an old thread, but another thing to consider regarding this issue is the IE security settings for the user account the ASP.NET application is running as. HTTP caching (CachePolicy.Level = Default, HTTP cacheable resources) was not working for our application until we added the remote host to the Trusted Sites list.

    This article was useful for our cache troubleshooting: http://blogs.msdn.com/b/ieinternals/archive/2011/03/19/wininet-temporary-internet-files-cache-and-explorer-folder-view.aspx

    0 讨论(0)
  • 2021-02-09 10:10

    I could be wrong but I would suspect that HttpWebRequest respects cache headers from the resource regardless of your stated desires.

    Check the response headers and ensure that the resource is not explicitly asking to not be cached.

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