Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core Web API FromHeader binding x-api-key header

I have a x-api-key header that I want to bind to my controller paramter. I tried the below code but the parameter is still null.

[HttpGet]
public ActionResult Get([FromHeader] xApiKey) {
    var apikey = xApiKey;
}
like image 323
Rod Talingting Avatar asked Sep 16 '25 03:09

Rod Talingting


1 Answers

After 5 minutes of posting this question I found the answer here. So using the name property of FromHeader.

[HttpGet]
public ActionResult Get([FromHeader(Name = "x-api-key")] apiKey) {
     // code here
}
like image 197
Rod Talingting Avatar answered Sep 18 '25 16:09

Rod Talingting