IIS 7.5 adds cache control response to cache cache

I use Azure and IIS 7.5 to serve my web application, but I do not use .NET.

I am trying to override the default cache value for my static files, but it looks like IIS 7.5 adds cache, no matter what I specify.

My approot / web.config file looks like this:

<?xml version="1.0"?> <configuration> <system.webServer> ... <staticContent> <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" /> </staticContent> ... </system.webServer> </configuration> 

and my answer headers:

 Accept-Ranges:bytes Access-Control-Allow-Origin:* Cache-Control:no-cache,public,max-age=2592000 Content-Encoding:gzip Content-Length:4309 Content-Type:application/x-javascript Date:Mon, 10 Sep 2012 14:42:07 GMT ETag:"8ccd2f95a8fcd1:0" Last-Modified:Mon, 10 Sep 2012 13:48:36 GMT Server:Microsoft-IIS/7.5 Vary:Accept-Encoding X-Powered-By:ASP.NET 

I have an additional web.config file in one of the subfolders, but this does not override any clientCache values.

Does anyone know why IIS adds cache?

Thanks!

+6
source share
2 answers

Apparently, the location attribute is needed for the output cache, otherwise it will override the staticContent / clientCache parameter.

 <system.webServer> ... <caching> <profiles> <add extension="*" policy="CacheForTimePeriod" duration="00:01:00" varyByQueryString="*" varyByHeaders="X-Requested-With" location="Any" /> </profiles> </caching> ... </system.webServer> 
+2
source

Based on your issue, I think you are using Windows Azure Cloud Services with a web role.

In this case, you need to use the Startup task to install Cache-Control in IIS, which will remain with the configuration of your website after launching the role. The command in the launch task should be as follows:

 appcmd.exe set config "Default Web Site/folder" -section:system.webServer/staticContent -clientCache.cacheControlCustom:public appcmd.exe set config "Default Web Site/folder" -section:system.webServer/staticContent -clientCache.cacheControlMode:UseMaxAge appcmd.exe set config "Default Web Site/folder" -section:system.webServer/staticContent -clientCache.cacheControlMaxAge:"30.00:00:00" 

If you want to learn how to use appcmd in a startup task, you can read this article.

0
source

Source: https://habr.com/ru/post/925045/


All Articles