HttpResponse does not contain definition for AddHeader for Dot Net Core

When moving a project to .Net Core, it AddHeader

gives an error:

Bug CS1061 "HttpResponse" does not contain a definition for "AddHeader", and no extension method "AddHeader" taking a first argument of type "HttpResponse" can be found (can you see using directive or assembly reference?). NETCoreApp, Version = v1.0

+3


source to share


2 answers


Checkout

Examples:



string combineValue = httpContext.Request.Headers["header1];
if (string.IsNullOrEmpty(combineValue)) // ...
var values = httpContext.Request.Headers["header1"];
if (StringValues.IsNullOrEmpty(values)) // ...
httpContext.Response.Headers["CustomHeader1"] = "singleValue";
httpContext.Response.Headers["CustomHeader2"] =  new[] { "firstValue", "secondValue" };

      

+2


source


The answer is to do the following instead (without using AddHeader):



Response.Headers["key-goes-here"] = "value-goes-here";

      

+2


source







All Articles