ASP.NET中的缓存控制标头不输出max-age

时间:2012-12-14 14:01:41

标签: asp.net .net asp.net-mvc http-headers cache-control

我有这段代码:

 context.HttpContext.Response.Cache.SetCacheability(HttpCacheability.Public);
 context.HttpContext.Response.Cache.SetMaxAge(TimeSpan.FromHours(24));

响应如下:

Status Code: 200
Date: Fri, 14 Dec 2012 13:56:41 GMT
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Length: 38436
X-AspNetMvc-Version: 4.0
Server: Microsoft-IIS/8.0
Content-Type: application/rss+xml; charset=utf-8
Cache-Control: public
X-SourceFiles: =?UTF-8?B?QzpcUHJvamVjdHNcVGVzdFxtYW5nb21pbnQucHVibGljXHNyY1xNYW5nb21pbnQuUHVibGljLldlYlxibG9nXHJzcw==?=

为什么Cache-Control上没有定义max-age?

1 个答案:

答案 0 :(得分:10)

我有同样的问题,这让我疯了。解决方案是首先添加此行:

context.HttpContext.Response.Cache.SetSlidingExpiration(true);