Sinaesthetic
Sinaesthetic

Reputation: 12241

how do i set the etag using the HttpResponseMessage object in mvc 4 web api?

I'm creating a bit of a helper class in my Web API project so I'm kind of stuck using HttpRequestMessage and HttpResponseMessage, or at least so it would seem. I've generated the eTag that I want to send back in the HttpResponseMessage, but I'm not sure where to add it to the object as everything has changed since WCF where I would simply use CheckConditionalRetrieve();

My question is, I have my eTag... lol... where do I put it using HttpResponseMessage???

TIA

Upvotes: 2

Views: 2107

Answers (1)

Sinaesthetic
Sinaesthetic

Reputation: 12241

I feel kinda silly. I've been looking for hours and just ran across it randomly. There are two Headers fields available in the request and response objects.

response.Headers

and

request.Content.Headers

The Etag property is in the top level Headers:

response.Headers.ETag

so my final code ended up being:

_response.Headers.ETag = new EntityTagHeaderValue(eTag);

Upvotes: 5

Related Questions