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

后端 未结 2 820
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-18 10:27

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

Error CS1061 \'HttpResponse\' does not contain a definition for \'Add

相关标签:
2条回答
  • 2021-01-18 10:50

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

    Response.Headers["key-goes-here"] = "value-goes-here";
    
    0 讨论(0)
  • 2021-01-18 10:56

    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" };
    
    0 讨论(0)
提交回复
热议问题