我有一个.Net 4.5.2 WebApi 2.2 REST服务。运行IIS 7.5的Windows 7机器。它没有多大作用,但返回当前日期/时间。当在IIS中承载的,我得到的是这样的响应头:WebApi 2.2 IIS 7.5设置max-age
HTTP/1.1 200 OK
Cache-Control: max-age=60
Content-Length: 58
Content-Type: application/json; charset=utf-8
ETag: "c664145c-6923-44b6-b3fb-ff7e50259b44"
Server: Microsoft-IIS/7.5
ApplicationDate: Test with date 4/3/2015 3:18:08 PM
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 03 Apr 2015 19:18:10 GMT
{"messages":[],"result":"All is well 4/3/2015 3:18:07 PM"}
如果我把它称为第二次,我看到:
HTTP/1.1 200 OK
Cache-Control: max-age=60
Content-Length: 58
Content-Type: application/json
ETag: "c664145c-6923-44b6-b3fb-ff7e50259b44"
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 03 Apr 2015 19:27:25 GMT
{"messages":[],"result":"All is well 4/3/2015 3:18:07 PM"}
我的自定义页眉(ApplicationDate)已经一去不复返了,时间没有改变。关键可能是Cache-Control:max-age = 60。我不知道它来自哪里!
如果我运行它“自我托管”,同样的代码...我看到这一点:
HTTP/1.1 200 OK
Content-Length: 58
Content-Type: application/json; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
ApplicationDate: Test with date 4/3/2015 3:35:31 PM
Date: Fri, 03 Apr 2015 19:35:31 GMT
{"messages":[],"result":"All is well 4/3/2015 3:35:30 PM"}
东西在IIS管道设置最大年龄。 (顺便说一句,用SoapUI和Fiddler测试,没有浏览器问题,使事情变得复杂)
我已经尝试禁用IIS OutputCache模块。我验证了使用FailedReqLogFiles:
OUTPUT_CACHE_LOOKUP_END 结果4 结果CACHING_DISABLED
当我改变缓存控制标头中的代码,我看到自托管版本的变化,但一些覆盖头在IIS版本回到最大年龄= 60。
HTTP/1.1 200 OK
Cache-Control: max-age=60
Pragma: no-cache
Content-Length: 58
Content-Type: application/json; charset=utf-8
ETag: "3ce2e8b6-4891-496e-8bb7-087590239d6b"
Server: Microsoft-IIS/7.5
ApplicationDate: Test with date 4/3/2015 3:49:19 PM
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 03 Apr 2015 19:49:19 GMT
{"messages":[],"result":"All is well 4/3/2015 3:49:19 PM"}
这里的控制器:
/// <summary>
/// Get "REST" status
/// </summary>
/// <returns></returns>
[ActionName("GetStatusDate")]
[Route("GetStatusDate")]
public HttpResponseMessage GetStatusDate()
{
CommonResponse<string> response = new CommonResponse<string>();
response.Result = "All is well " + DateTime.Now;
HttpResponseMessage responseMessage = Request.CreateResponse(HttpStatusCode.OK, response);
responseMessage.Headers.Add("ApplicationDate", "Test with date " + DateTime.Now);
responseMessage.Headers.Remove("Cache-Control");
responseMessage.Headers.CacheControl = new CacheControlHeaderValue()
{
MaxAge = TimeSpan.FromSeconds(11),
NoCache = true,
Private = true
};
responseMessage.Headers.Add("Pragma","no-cache");
return responseMessage;
}
什么是设置最大年龄?
感谢,
肖恩
所以,你做了什么来做到这一点? – Coder 2017-01-18 07:00:36