How to specify HTTP expiration header? (ASP.NET MVC+IIS)

后端 未结 3 1180
遥遥无期
遥遥无期 2020-12-22 19:11

I am already using output caching in my ASP.NET MVC application.

Page speed tells me to specify HTTP cache expiration for css and images in the response header.

相关标签:
3条回答
  • 2020-12-22 19:20

    Found it:

    I need to specify client cache for static content (in web.config).

    <configuration>
      <system.webServer>
        <staticContent>
          <clientCache cacheControlCustom="public" 
          cacheControlMaxAge="12:00:00" cacheControlMode="UseMaxAge" />
        </staticContent>
       </system.webServer>
    </configuration>
    

    from http://www.iis.net/ConfigReference/system.webServer/staticContent/clientCache

    0 讨论(0)
  • 2020-12-22 19:39

    Look at mini static content delivery project. :)

    0 讨论(0)
  • 2020-12-22 19:43

    If you want to do it from code for a resource that you're returning (ie. not a static file being served from IIS), you're better off using Response.Cache:

    Response.Cache.SetExpires(DateTime.Now.AddYears(1));
    Response.Cache.SetCacheability(HttpCacheability.Public);
    

    I know that's not exactly what you're asking for, but I found this question via Google and figure others might like this answer as it's related to the APIs you show in the original question text.

    0 讨论(0)
提交回复
热议问题