How to extract custom header value?

后端 未结 1 1325
春和景丽
春和景丽 2020-12-15 15:18

I have this exact code from the accepted answer in my project which I need to migrate into ASP.NET Core MVP.

How to extract custom header value in Web API message ha

相关标签:
1条回答
  • 2020-12-15 15:30

    Request.Headers returns Microsoft.AspNetCore.Http.IHeaderDictionary interface that define next property:

    StringValues this[string key] { get; set; }
    

    IHeaderDictionary has a different indexer contract than IDictionary, where it will return StringValues.Empty for missing entries.

    Return type: Microsoft.Extensions.Primitives.StringValues

    Returns: The stored value, or StringValues.Empty if the key is not present.

    So, you can simply use Request.Headers["environment"] to get value of "environment" header

    0 讨论(0)
提交回复
热议问题