【问题标题】:IIS cache all files with a certain extension using web.configIIS 使用 web.config 缓存具有特定扩展名的所有文件
【发布时间】:2015-11-15 19:00:30
【问题描述】:

在我的网络配置中,我将所有内容缓存在某个文件夹中,就像这样

 <location path="img">
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
    </staticContent>
</system.webServer>

但是我的 css 和 js 不在某些文件夹中,我希望能够使用这样的通配符:

*.js,*.css,*.png,*.jpg

有什么方法可以通过 web.config 在 IIS 中执行此操作吗?

【问题讨论】:

    标签: http caching iis web-config server


    【解决方案1】:

    对于我的用例,我想缓存除 html 之外的所有静态文件。 (这有时被称为缓存破坏)

    为了使其工作,html 文件不能是staticContent 的一部分。为 html 文件添加新的处理程序可防止它们被永久缓存。

        <staticContent>
            <clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
        </staticContent>
        <handlers>
          <add
            name="HtmlHandler"
            path="*.html"
            verb="*"
            type="System.Web.Handlers"
            preCondition="integratedMode"
          />
        </handlers>
    

    【讨论】:

      猜你喜欢
      • 2019-06-14
      • 1970-01-01
      • 1970-01-01
      • 2012-05-22
      • 2020-02-13
      • 1970-01-01
      • 2022-11-15
      • 2022-08-11
      • 1970-01-01
      相关资源
      最近更新 更多