IIS7禁用單個靜態文件的緩存配置方法

IIS7中,想將一個常常修改的靜態文件設置爲不可緩存,在IIS配置界面裏怎麼也找不到...web

一番google以後在stackoverflow裏邊發現了這樣一段回答,最終解決了問題:緩存

 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]

按照回答中的方法在web.config裏邊進行配置,再訪問,在header裏邊就能夠看到this

Cache-Control:no-cachegoogle

了,證實配置生效~spa

相關文章
相關標籤/搜索