【问题标题】:c# cache control for .jpg, .css, .js...c# .jpg、.css、.js 的缓存控制...
【发布时间】:2017-07-01 16:25:20
【问题描述】:

我分析了我的网站,并针对文件 .css、.js、.png、.jpg 等出现此错误“未指定过期时间”。

我为 php 找到了这个

<IfModule mod_headers.c>
<FilesMatch "\.(jpg|jpeg|png|gif|swf|js|css|swf)$">
    Header set Cache-Control "max-age=604800, public"
</FilesMatch>

C# 中的等价物是什么?而且,我应该在 web.config 中编码吗?

提前致谢。

【问题讨论】:

    标签: c# caching browser-cache


    【解决方案1】:

    您需要在 IIS 配置的 staticContent 块中设置 clientCache

    <system.webServer>
        <staticContent>
          <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
        </staticContent>
      </system.webServer>
    

    这会将有效期设置为 30 天。

    详细解释可以看here

    【讨论】:

    • 非常感谢您,这项工作很好! @NutcaseDeveloper
    猜你喜欢
    • 1970-01-01
    • 2011-03-15
    • 1970-01-01
    • 1970-01-01
    • 2011-11-12
    • 2011-11-01
    • 2014-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多