Search code examples
asp.netiisiis-7cache-controloutputcache

Where is my max-age header coming from?


I'm well aware of how I could set it myself, but I am concerned about having it configured in two different places. To receive the bounty, please tell me where I should look to find the existing setting.

Places we've already looked for the existing setting, without success:

  • the web.config <StaticContent> section
  • IIS output caching section, at all three levels:
    • machine
    • site
    • application
  • Code (I did a global search for SetMaxAge)

Context

We recently noticed that our CSS and JS files aren't getting refreshed. When I inspect the network traffic, they are coming back from the server with a header (Cache-Control: max-age=604800) that gives them a seven-day lifespan.

We need to reduce the cache lifetime. But for the life of me I can't find where it is set.

It is not set in the web.config <StaticContent> section.

It is not set in the IIS output caching section (I looked under the machine, the site, and the application-- they are all blank).

It is not set in code-- I did a global code search for SetMaxAge and got nuthin'. Where else can I look?

Is it possible it is being set by the gateway or load balancer in our data center?


Solution

  • You can do like this in web config, or you can use IIS ui to change (see link below):

    <configuration>
      <system.webServer>
        <staticContent>
           <clientCache cacheControlMode="UseMaxAge"
            cacheControlMaxAge="1.00:00:00" /> <!-- 1 day -->
        </staticContent>
      </system.webServer>
    </configuration>
    

    See more here: https://www.iis.net/configreference/system.webserver/staticcontent/clientcache

    IIS documentation states that the default value is 1 day.

    Here are some other ways what could have affect these settings: http://www.galcho.com/blog/post/2008/02/27/IIS7-How-to-set-cache-control-for-static-content.aspx

    • overrideModeDefault value in applicationHost.config
    • earlier appcmd.exe settings
    • or client setting can also override your values.