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

前端之家收集整理的这篇文章主要介绍了azure – 如何将设置应用于IIS中的特定扩展?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在Azure上使用以下Web.config托管Web应用程序:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3. <system.webServer>
  4. <staticContent>
  5. <mimeMap fileExtension=".text" mimeType="text/plain" />
  6. <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
  7. </staticContent>
  8. </system.webServer>
  9. </configuration>

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

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

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

解决方法

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

这是配置.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3. <system.webServer>
  4. <staticContent>
  5. <mimeMap fileExtension=".text" mimeType="text/plain" />
  6. <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
  7. </staticContent>
  8. <rewrite>
  9. <outboundRules>
  10. <rule name="RewriteCacheControlForHTMLFiles" preCondition="FileEndsWithHtml">
  11. <match serverVariable="RESPONSE_Cache_Control" pattern=".*" />
  12. <action type="Rewrite" value="max-age=86400" />
  13. </rule>
  14. <preConditions>
  15. <preCondition name="FileEndsWithHtml">
  16. <add input="{REQUEST_FILENAME}" pattern="\.html$" />
  17. </preCondition>
  18. </preConditions>
  19. </outboundRules>
  20. </rewrite>
  21. </system.webServer>
  22. </configuration>

我测试的截图:

猜你在找的HTML相关文章