gpt4 book ai didi

asp.net - 获取Asp.net/iis以设置静态文件的Cache-control:max-age

转载 作者:行者123 更新时间:2023-12-03 13:17:42 28 4
gpt4 key购买 nike

我们有一个带有网址路由的Webforms项目。我已经定义了图像和css文件的异常路由为

routes.Add("IgnoreImages", new Route("img/{*pathInfo}", new StopRoutingHandler()));
routes.Add("IgnoreCss", new Route("css/{*pathInfo}", new StopRoutingHandler()));

因此,静态文件应由IIS直接提供服务,并且应绕过路由。

使用Fiddler检查图像的响应时,“缓存”标题下的唯一键是“日期”。缺少的是Cache-control:max:age键。如何为静态文件指定缓存策略?该应用程序在IIS7.5上运行。

最佳答案

解决方案是使用web.config文件中的system.webserver部分配置服务器缓存(和压缩)。这是一个起点:http://www.iis.net/ConfigReference/system.webServer/staticContent/clientCache

例:

<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge"
cacheControlMaxAge="1.00:00:00" /> <!-- 1 day -->
</staticContent>
</system.webServer>
</configuration>

关于asp.net - 获取Asp.net/iis以设置静态文件的Cache-control:max-age,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6251219/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com