Where all types for http headers gone in ASP.NET 5?
If you add the using statement for Microsoft.AspNetCore.Http
, there are extension methods on the HttpRequest
and HttpResponse
to GetTypedHeaders
, which should give you the type safety that you want.
In the example, I also added the using statement for Microsoft.Net.Http.Headers
, just to clean it up.
var headers = Response.GetTypedHeaders();
headers.ContentType = new MediaTypeHeaderValue("text/cache-manifest");
headers.CacheControl = new CacheControlHeaderValue { NoCache = true, Public = true };
headers.ETag = new EntityTagHeaderValue("\"" + etag + "\"");
Source: aspnet/HttpAbstractions on Github
In Asp.net 5 the headers collection is now a single class i.e. HeaderDictionary
that can be used for both request and response headers. This will act as a key value based store for headers. The good reason I can see is because of Owin support. One store can be used utilized across various Owin supported middleware e.g. WebApi, SignalR which provides you extensibility for adding more information in Header collection.