IIS7 iis7.5 configuration method that disables caching of single static files
- 2020-06-07 05:43:01
In IIS7, if you want to make a static file that is frequently modified non-cache, you can't find it in the IIS configuration screen.
After the first google, the following paragraph was found in stackoverflow, which finally solved the problem:
1. Disallow caching of individual files
just stumbled across this question; you can use the following to disable the cache on a specific file:
Once in a while, you can disable caching for individual files by using the following method
<configuration> <location path="path/to/the/file"> <system.webServer> <staticContent> <clientCache cacheControlMode="DisableCache" /> </staticContent> </system.webServer> </location> </configuration>
(Note that the path is relative to the web.config file)
Note that the path needs to be written relative to the path of the web.config file
Alternatively, place the single file in a directory on it's own, and give that directory it's own web.config that disables caching for everything in it;
Or put the file in a separate directory and disable caching with its own web.config file.
2. By placing files in a directory, the files in this directory will not be cached
<configuration> <system.webServer> <httpProtocol> <customHeaders> <add name="Cache-Control" value="no-cache" /> </customHeaders> </httpProtocol> </system.webServer> </configuration>
[Both tested on IIS7.5 on Windows 7, but you'll have to confirm that it works OK on Azure]
The iis7.5 cache in win7 has also been tested, but you need to make sure it works on Azure.