How do I disable caching of an individual file in IIS 7 using weserver config settings How do I disable caching of an individual file in IIS 7 using weserver config settings xml xml

How do I disable caching of an individual file in IIS 7 using weserver config settings


I just stumbled across this question; you can use the following to disable the cache on a specific file:

<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)

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;

<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]


Looks like the above answer is missing a "profiles" tag

<caching>  <profiles>    <add extension=".js" kernelCachePolicy="DontCache" policy="DontCache"/>  </profiles></caching>


You're going to want to look at the System.WebServer/Caching class, where you can apply a caching profile to particular extensions. This will at least enable you to control it for all Javascript files ending with the .js.

<system.webServer>...   <caching>      <add extension=".js" policy="DontCache" kernelCachePolicy="DontCache" />   </caching></system.webServer>

That should disable .js caching on both process and kernel caching from the cloud.

I think you can create this web.config in a folder that contains just your file and it will disable caching for .js only at that folder level. I honestly have not tried that myself, so just a suggestion you could test.


Beyond that, take a look at the documentation for IIS related to caching config:

/Caching: http://www.iis.net/ConfigReference/system.webServer/caching

/Caching/Profiles: http://www.iis.net/ConfigReference/system.webServer/caching/profiles

/Caching/Profiles/Add: http://www.iis.net/ConfigReference/system.webServer/caching/profiles/add

Hopefully that, plus some research on those config tags will help.

If not, I'd recommend looking into implementing a custom HTTP Module that you can insert into the IIS request pipe, which can filter your caching control down to that particular file

** for what its worth this is just IIS behavior and won't be different in or out of Azure, so you could easily test this local without bothering with the Dev fabric or Azure testing.