Asp.net web api WebApi 2.2 IIS 7.5某些内容正在设置最大年龄

Asp.net web api WebApi 2.2 IIS 7.5某些内容正在设置最大年龄,asp.net-web-api,iis-7.5,Asp.net Web Api,Iis 7.5,我有一个.NET4.5.2WebAPI 2.2REST服务。运行IIS 7.5的Windows 7计算机。它只返回当前的日期/时间,没有太多功能。在IIS中托管时,我会收到如下响应头: 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" Serve

我有一个.NET4.5.2WebAPI 2.2REST服务。运行IIS 7.5的Windows 7计算机。它只返回当前的日期/时间,没有太多功能。在IIS中托管时,我会收到如下响应头:

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"}
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"}
我的自定义标题ApplicationDate已经消失,时间也没有改变。关键可能是缓存控件:其中的max age=60。我不知道它是从哪里来的

如果我运行自托管的相同代码,我会看到:

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"}
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进行了验证:

输出\缓存\查找\结束 结果4 结果缓存被禁用

当我在代码中更改缓存控制头时,我会看到自托管版本中的更改,但某些内容会将IIS版本中的头覆盖回max age=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;

}
什么是设置最大年龄

谢谢


Sean

所以,我应该再等一个小时再发布这个问题……问题是CacheOutputAttribute OutputCache.V2不仅是在特定资源上设置的,而且已经添加到全局筛选器集合中。因为它继承了FilterAttribute,IActionFilter,所以它作为一个全局过滤器工作得很好。这就是为什么所有调用都被缓存的原因。把这个项目搞得一文不值才找到问题所在


肖恩

那么,你是怎么做到的?