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

Mat*_*und 18 asp.net caching image cache-control

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

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

所以静态文件应该由IIS直接提供,并且应该绕过路由.

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

Dar*_*era 28

解决方案是使用system.webserverweb.config文件中的部分来配置服务器缓存(和压缩).这是一个起点: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>
Run Code Online (Sandbox Code Playgroud)


Eva*_*aas 16

达里奥的回答让我最的方式,但我不得不添加的属性<clientCache>,cacheControlCustom="public"否则IIS没有的Cache-Control头发送到浏览器.看到这个答案.