如何指定HTTP过期标头? (ASP.NET MVC + IIS)

问题描述:

我已经使用输出缓存在我的ASP.NET MVC应用程序。

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

网页速度告诉我指定的CSS和图像在响应头HTTP缓存过期

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

我知道Response对象包含一些属性控制缓存过期。我知道,这些属性可以用来控制HTTP缓存响应,我的从我的code服务:

I know that the Response object contains some properties that control cache expiration. I know that these properties can be used to control HTTP caching for response that I am serving from my code:

Response.Expires
Response.ExpiresAbsolute
Response.CacheControl

或备选

Response.AddHeader("Expires", "Thu, 01 Dec 1994 16:00:00 GMT");

问题为如何设置为自动服务资源,例如Expires头图片,CSS等?

发现:

我需要指定静态内容(在web.config中)客户端缓存。

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>

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