goamn
goamn

Reputation: 2126

HttpResponse does not contain a definition for AddHeader for Dot Net Core

When moving a project into .Net Core, AddHeader throws an error:

Error CS1061 'HttpResponse' does not contain a definition for 'AddHeader' and no extension method 'AddHeader' accepting a first argument of type 'HttpResponse' could be found (are you missing a using directive or an assembly reference?) .NETCoreApp,Version=v1.0

Upvotes: 8

Views: 13787

Answers (3)

Juvinal Alvarado
Juvinal Alvarado

Reputation: 21

Or you can just say:

Response.Headers.Add("key", "value");

Upvotes: 1

goamn
goamn

Reputation: 2126

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

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

Upvotes: 9

McKabue
McKabue

Reputation: 2222

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" };

Upvotes: 3

Related Questions