服务器 
首页 > 服务器 > 浏览文章

IIS7、iis7.5中禁止缓存单个静态文件的配置方法

(编辑:jimmy 日期: 2024/10/19 浏览:3 次 )

IIS7中,想将一个经常修改的静态文件设置为不可缓存,在IIS配置界面里怎么也找不到...

一番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)
注意路径的写法需要相对于web.config文件的路径
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;
或者是将这个文件放一个单独的目录里面,然后通过它自己的web.config文件来禁用缓存。

二、通过将文件放到一个目录里面进行设置,这个目录里的文件都不会缓存

<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]
在win7中的iis7.5缓存也测试过,不过你需要确认他在Azure能否正常运行。

上一篇:解决Ubuntu 16.04下提示boot分区空间不足的办法
下一篇:在Centos7中安装Docker1.12的详细教程
一句话新闻
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap