Previously, in WebApi (on .NET 4.x) we could work with headers of both the request and the response via typed interfaces (see HttpRequestMessage.Headers
/HttpResponseMessage.Headers
).
Now, in ASP.NET 5 we have HttpRequest
and HttpResponse
with Headers property of type IHeaderDictionary
. But it's just an untyped Dictionary.
Below I put an example with typed accessing could return a fine-tuned http-response. It's needed to create a HttpResponseMessage
and fill its Headers collection (which was typed btw).
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(manifestContent);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/cache-manifest");
response.Headers.CacheControl = new CacheControlHeaderValue {NoCache = true, Public = true};
response.Headers.ETag = new EntityTagHeaderValue("\"" + etag + "\"");