在IIS的Output caching中如果启用了User-mode caching将引起Cache-Control为no-cache,从而造成页面不能被浏览器或代理服务器缓存,下面看解决方法

IIS中设置Cache-Control

IIS中设置Cache-Control


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>

 

浏览器中看到的效果:

IIS中设置Cache-Control

解决方法:

1、禁用User-mode caching,只用Kernel-mode caching。

IIS中设置Cache-Control

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>

相关文章:

  • 2021-10-16
  • 2021-07-15
  • 2021-08-11
  • 2022-12-23
  • 2021-07-09
猜你喜欢
  • 2022-12-23
  • 2021-11-27
  • 2021-12-19
  • 2021-09-27
  • 2021-11-21
相关资源
相似解决方案