IIS7、iis7.5中禁止缓存单个静态文件的配置方法
IIS7中,想将一个经常修改的静态文件设置为不可缓存,在IIS配置界面里怎么也找不到...
一番google之后在stackoverflow里边发现了这样一段回答,最终解决了问题:
一、单个文件的禁止缓存的方法
juststumbledacrossthisquestion;youcanusethefollowingtodisablethecacheonaspecificfile:
偶尔看到这个问题,你可以通过下面的方法来对单个文件进行禁止缓存
<configuration> <locationpath="path/to/the/file"> <system.webServer> <staticContent> <clientCachecacheControlMode="DisableCache"/> </staticContent> </system.webServer> </location> </configuration>
(Notethatthepathisrelativetotheweb.configfile)
注意路径的写法需要相对于web.config文件的路径
Alternatively,placethesinglefileinadirectoryonit'sown,andgivethatdirectoryit'sownweb.configthatdisablescachingforeverythinginit;
或者是将这个文件放一个单独的目录里面,然后通过它自己的web.config文件来禁用缓存。
二、通过将文件放到一个目录里面进行设置,这个目录里的文件都不会缓存
<configuration> <system.webServer> <httpProtocol> <customHeaders> <addname="Cache-Control"value="no-cache"/> </customHeaders> </httpProtocol> </system.webServer> </configuration>
[BothtestedonIIS7.5onWindows7,butyou'llhavetoconfirmthatitworksOKonAzure]
在win7中的iis7.5缓存也测试过,不过你需要确认他在Azure能否正常运行。