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

标签 asp.net image caching cache-control

我们有一个带有网址路由的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/

相关文章:

asp.net - URL 重写 - web.config 错误

python - 关于hough_line和hough_line_peaks的代码解释

css - div中的图像不显示任何内容

html - CSS 边框图像显示模糊

ASP.NET数据缓存设计

c# - 命名空间中不存在类型或命名空间名称 'DirectoryServices'?

asp.net - 配置 IIS 以进行 SAML 身份验证

c# - 尽管数据表存储在缓存中,但每次使用后是否都必须调用 dispose?

c# - 使用自定义分页优化搜索 SQL

node.js - 在 hapi 中设置缓存头