我想在ASP.NET Web Api操作中实现CacheControl头信息(我知道可以使用其他库以及过滤器/处理程序来完成此操作,但是我想先进行一些测试)。
我正在按照一本书上的简单示例进行尝试,示例代码如下:
var response = Request.CreateResponse<IEnumerable<string>>(HttpStatusCode.OK,emails);
response.Headers.CacheControl = new CacheControlHeaderValue();
response.Headers.CacheControl.MaxAge = TimeSpan.FromHours(1);
response.Headers.CacheControl.MustRevalidate = false;
response.Headers.CacheControl.Public = true;
return response;
这段代码与stackoverflow上提供的一些其他答案几乎完全相同。
然而,web api根本未设置缓存控制头! 有什么想法吗????
当我在fiddler中查看响应时,它看起来像下面这样,你可以看到缓存控制设置为no-cache。
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-MiniProfiler-Ids: ["b7bfde10-e8d3-455d-b40d-2f33eb285023"]
X-Powered-By: ASP.NET
Date: Sat, 25 May 2013 11:54:35 GMT
Content-Length: 24
我已经尝试更改maxage、mustrevalidate和public的值,但都无济于事...