Last post Mar 17, 2012 03:07 PM by Vistor
Feb 28, 2012 11:34 AM|awebb|LINK
I have migrated my code from WCF Web API preview 6 to ASP.NET Web API. There's one remaining issue: setting ETag and Last-Modified response headers in my controller actions
doesn't result in these headers appearing in the response received by the client. It worked fine in WCF.
E.g. I do this in an action:-
if (result.LastModified != null)
response.Content.Headers.LastModified = result.LastModified.Value.ToUniversalTime();
if (result.SequenceNumber != null)
response.Headers.ETag = new EntityTagHeaderValue
("\"" + result.SequenceNumber.Value.ToString(CultureInfo.InvariantCulture) + "\"", false);
When these two statements are executed, no such headers appear in the response. E.g. Fiddler gets this:-
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Tue, 28 Feb 2012 16:23:48 GMT
Content-Type: application/vnd.statpro.revolution.wapi.portfolios+json; charset=utf-8
Attempting to set other headers does work. E.g. I set the Location header to some random URI (http://www.google.com), and Fiddler did receive the Location header set to that value.
Bug? Or am I missing something?
Feb 28, 2012 12:13 PM|Kiran Challa|LINK
I have tried the following and setting these headers works....
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Last-Modified: Tue, 28 Feb 2012 17:05:51 GMT
Date: Tue, 28 Feb 2012 17:05:51 GMT
public HttpResponseMessage GetString()
HttpResponseMessage response = new HttpResponseMessage();
response.Headers.ETag = new EntityTagHeaderValue("\"686897696a7c876b7e\"");
response.Content = new StringContent("hello");
response.Content.Headers.LastModified = DateTime.Now.ToUniversalTime();
Feb 28, 2012 12:18 PM|davebettin|LINK
It looks like this an issue with Cassini. Headers are set properly in IIS and IIS Express but not in Cassini. I would switch your API over to use IIS Express and it should work without any issues.
Feb 29, 2012 05:01 AM|awebb|LINK
It looks like this an issue with Cassini.
Thanks Dave. Yes, it's Cassini. Or rather the combination of ASP.NET Web API and Cassini, because this was working in WCF.
No matter... I will use IIS Express from now on.
Mar 17, 2012 03:07 PM|Vistor|LINK
Cassini ignores ETag and Last-Modified headers if Cache-Control is 'private', which it is by default. Changing Cache-Control to 'public' causes both ETag and Last-Modified appear on the client correctly.