加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

azure – 如何将设置应用于IIS中的特定扩展?

发布时间:2020-12-14 18:29:18 所属栏目:资源 来源:网络整理
导读:我在Azure上使用以下Web.config托管Web应用程序: ?xml version="1.0" encoding="UTF-8"?configuration system.webServer staticContent mimeMap fileExtension=".text" mimeType="text/plain" / clientCache cacheControlCustom="public" cacheControlMode=
我在Azure上使用以下Web.config托管Web应用程序:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".text" mimeType="text/plain" />
      <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
    </staticContent>
  </system.webServer>
</configuration>

这有效,但我想通过扩展来改变缓存时间.我想将.html文件的最大年龄设置为1天,将其他所有文件的最大年龄设置为365天.原因是html中的所有资产都有其文件名在更改时加速并且是从CDN提供的,所以它们永远不需要过期,但是html页面本身需要始终保持新鲜,以便用户可以看到新内容.

我看到< location> element允许将Web.config过滤到特定位置,但我没有看到将其限制为某些扩展的方法.

请注意,我不需要在Web.config中执行此操作:使用Azure Web App可能的任何方法都可以.

解决方法

正如其他人所说,这是不可能的,所以我想建议一个解决方法来完成这项工作.
您可以通过创建出站规则来替换html文件的Cache-Control标头,从而利用URL重写模块的功能.

这是配置.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <staticContent>
            <mimeMap fileExtension=".text" mimeType="text/plain" />
            <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
        </staticContent>
        <rewrite>
            <outboundRules>
                <rule name="RewriteCacheControlForHTMLFiles" preCondition="FileEndsWithHtml">
                    <match serverVariable="RESPONSE_Cache_Control" pattern=".*" />
                    <action type="Rewrite" value="max-age=86400" />
                </rule>
                <preConditions>
                    <preCondition name="FileEndsWithHtml">
                        <add input="{REQUEST_FILENAME}" pattern=".html$" />
                    </preCondition>
                </preConditions>
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

我测试的截图:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读