Skip to main content

Disable static file caching from path or individual resource in ASP.NET Web.config file.

<!-- To disable static file caching of resource (path/to/userguide.pdf) -->
<?xml version="1.0" encoding="utf-8"?>
...
<configuration>
  <location path="path/to/userguide.pdf">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="DisableCache" />
      </staticContent>
    </system.webServer>
  </location>
</configuration>

<!-- To disable all static file caching in path -->
<!-- 1. Add Web.config to the target directory. -->
<!-- 2. Add the following snippet:              -->
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Cache-Control" value="no-cache" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>