Getting a Request.Headers value

后端 未结 7 1072
忘了有多久
忘了有多久 2020-12-01 07:33

Very simple I\'m sure, but driving me up the wall! There is a component that I use in my web application that identifies itself during a web request by adding the header \"X

7条回答
  •  不知归路
    2020-12-01 08:04

    In dotnet core, Request.Headers["X-MyCustomHeader"] returns StringValues which will not be null. You can check the count though to make sure it found your header as follows:

    var myHeaderValue = Request.Headers["X-MyCustomHeader"];
    if(myHeaderValue.Count == 0) return Unauthorized();
    string myHeader = myHeaderValue.ToString(); //For illustration purposes.
    

提交回复
热议问题