简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM