lundi 6 avril 2015

WebApi 2.2 IIS 7.5 something is setting max-age


Vote count:

0




I have a .Net 4.5.2 WebApi 2.2 REST service. Windows 7 machine running IIS 7.5. It doesn't do much but return the current date/time. When hosted in IIS, I get response headers that look like this:



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"}


If I call it a second time, I see this:



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"}


My custom header (ApplicationDate) is gone, and the time hasn't changed. The key is probably the Cache-Control: max-age=60 in there. I don't know where it's coming from!


If I run it "Self Hosted", same code...I see this:



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"}


Something in the IIS pipeline is setting max-age. (BTW, testing with SoapUI and Fiddler, no browser issues to complicate things)


I have tried disabling the IIS OutputCache module. I verified using FailedReqLogFiles:


OUTPUT_CACHE_LOOKUP_END Result 4 Result CACHING_DISABLED


When I change the cache-control headers in code, I see the changes in the Self-Hosted version, but something overwrites the headers in the IIS version back to 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"}


Here's the controller:



/// <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;

}


What is setting max-age?


Thanks,


Sean



asked 31 secs ago







WebApi 2.2 IIS 7.5 something is setting max-age

Aucun commentaire:

Enregistrer un commentaire