IIS7: set “no-cache” for all aspx pages but not images/css/js

前端 未结 3 964
迷失自我
迷失自我 2021-01-03 00:03

I would like to not cache my aspx pages anywhere. For some reason IE ignores meta tags which are set from my master page



        
3条回答
  •  梦毁少年i
    2021-01-03 01:02

    If you are using a MasterPage for your site, you may want to consider adding the following response header to its Page_Load event:

    protected void Page_Load(object sender, EventArgs e)
    {
    Response.AddHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
    }
    

    Since your .js file(s) will not use the MasterPage, the browser should save the reference to its cache.

    The example above is what I use and it works well under Firefox3, IE7, and Chrome7. Note that the response header above is the only thing I added for cache control and it does the job. However, I often see Pragma and Expires response headers on other websites.

    For example, here is the response headers that are used in Gmail:

    Content-Type: text/html; charset=UTF-8
    Cache-Control: no-cache, no-store, max-age=0, must-revalidate
    Pragma: no-cache
    Expires: Fri, 01 Jan 1990 00:00:00 GMT

    Date: Tue, 02 Nov 2010 16:38:15 GMT
    x-dns-prefetch-control: off
    Content-Encoding: gzip
    Transfer-Encoding: chunked
    X-Content-Type-Options: nosniff
    X-Frame-Options: SAMEORIGIN
    X-XSS-Protection: 1; mode=block
    Server: GSEServer: GSE

    I'm not sure if those are used for older browsers and/or other newer browsers.

    I prefer to implement the minimum amount of code to solve a problem and I've never (yet) had a case where the Response.AddHeader noted at the top wasn't sufficient.

提交回复
热议问题