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
X-AspNet-Version: 4.0.30319
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Content-Type: application/vnd.statpro.revolution.wapi.portfolios+json; charset=utf-8
Connection: Close
Content-Length: 5909
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.
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.
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.
Member
81 Points
90 Posts
ETag and Last-Modified values not appearing in response.
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:-
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
X-AspNet-Version: 4.0.30319
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Content-Type: application/vnd.statpro.revolution.wapi.portfolios+json; charset=utf-8
Connection: Close
Content-Length: 5909
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?
Participant
781 Points
301 Posts
Microsoft
Re: ETag and Last-Modified values not appearing in response.
Feb 28, 2012 12:13 PM|Kiran Challa|LINK
I have tried the following and setting these headers works....
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/plain; charset=utf-8
Expires: -1
Last-Modified: Tue, 28 Feb 2012 17:05:51 GMT
ETag: "686897696a7c876b7e"
Server: Microsoft-IIS/7.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 28 Feb 2012 17:05:51 GMT
Content-Length: 5
hello
Kiran Challa
Member
131 Points
93 Posts
Re: ETag and Last-Modified values not appearing in response.
Feb 28, 2012 12:18 PM|davebettin|LINK
Howdy,
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.
Cheers,
Dave
@dbettin
Member
81 Points
90 Posts
Re: ETag and Last-Modified values not appearing in response.
Feb 29, 2012 05:01 AM|awebb|LINK
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.
None
0 Points
9 Posts
Re: ETag and Last-Modified values not appearing in response.
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.
-Vitaly