为了账号安全,请及时绑定邮箱和手机立即绑定

如何在IIS7中为每个文件夹和扩展配置静态内容缓存?

如何在IIS7中为每个文件夹和扩展配置静态内容缓存?

如何在IIS7中为每个文件夹和扩展配置静态内容缓存?我想在IIS7中为我的ASP.NET网站中的静态内容缓存设置规则。我已经看过这些文章,详细介绍了如何使用以下<clientCache />元素web.config:客户端缓存<clientCache>(IIS.NET)将过期或缓存控制标头添加到IIS中的静态内容(堆栈溢出)但是,此设置似乎全局适用于所有静态内容。有没有办法只为某些目录或扩展这样做?例如,我可能有两个需要单独缓存设置的目录:/static/images/content/pdfs是否有可能建立规则发送缓存头(max-age,expires基于扩展和文件夹路径等)?请注意,我必须能够这样做,web.config因为我无法访问IIS控制台。
查看完整描述

3 回答

?
守着一只汪

TA贡献1872条经验 获得超3个赞

您可以在根目录中为整个文件夹设置特定的缓存标头web.config

<?xml version="1.0" encoding="UTF-8"?><configuration>
  <!-- Note the use of the 'location' tag to specify which 
       folder this applies to-->
  <location path="images">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
      </staticContent>
    </system.webServer>
  </location></configuration>

或者您可以web.config在内容文件夹中的文件中指定这些:

<?xml version="1.0" encoding="UTF-8"?><configuration>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
    </staticContent>
  </system.webServer></configuration>

我不知道内置机制来定位特定的文件类型。


查看完整回答
反对 回复 2019-07-29
?
犯罪嫌疑人X

TA贡献2080条经验 获得超4个赞

您可以基于每个文件执行此操作。使用path属性包含文件名

<?xml version="1.0" encoding="UTF-8"?><configuration>
    <location path="YourFileNameHere.xml">
        <system.webServer>
            <staticContent>
                <clientCache cacheControlMode="DisableCache" />
            </staticContent>
        </system.webServer>
    </location></configuration>


查看完整回答
反对 回复 2019-07-29
  • 3 回答
  • 0 关注
  • 760 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信