IIS中User-mode caching引起的Cache-Control不为public问题的解决方法
程序员文章站
2022-05-24 18:27:50
web.config中对应的配置如下:
复制代码 代码如下:
<configuration>
<system.webserver>
<caching>
<profiles>
<add extension=".css" policy="cacheuntilchange" kernelcachepolicy="cacheuntilchange" duration="00:00:30" />
<add extension=".js" policy="cacheuntilchange" kernelcachepolicy="cacheuntilchange" duration="00:00:30" />
</profiles>
</caching>
</system.webserver>
</configuration>
<configuration>
<system.webserver>
<staticcontent>
<clientcache cachecontrolcustom="public" cachecontrolmode="usemaxage" cachecontrolmaxage="300.00:00:00" />
</staticcontent>
<caching>
<profiles>
<add extension=".css" policy="dontcache" kernelcachepolicy="cacheuntilchange" duration="30:00:30" />
<add extension=".js" policy="dontcache" kernelcachepolicy="cacheuntilchange" duration="30:00:30" />
</profiles>
</caching>
</system.webserver>
</configuration>
web.config中对应的配置如下:
复制代码 代码如下:
<configuration>
<system.webserver>
<caching>
<profiles>
<add extension=".css" policy="cacheuntilchange" kernelcachepolicy="cacheuntilchange" duration="00:00:30" />
<add extension=".js" policy="cacheuntilchange" kernelcachepolicy="cacheuntilchange" duration="00:00:30" />
</profiles>
</caching>
</system.webserver>
</configuration>
浏览器中看到的效果:
解决方法:
1、禁用user-mode caching,只用kernel-mode caching。
2、在web.config中加上cachecontrolcustom="public"
复制代码 代码如下:
<configuration>
<system.webserver>
<staticcontent>
<clientcache cachecontrolcustom="public" cachecontrolmode="usemaxage" cachecontrolmaxage="300.00:00:00" />
</staticcontent>
<caching>
<profiles>
<add extension=".css" policy="dontcache" kernelcachepolicy="cacheuntilchange" duration="30:00:30" />
<add extension=".js" policy="dontcache" kernelcachepolicy="cacheuntilchange" duration="30:00:30" />
</profiles>
</caching>
</system.webserver>
</configuration>
上一篇: 让IIS8支持WCF的更简单方法