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;
}
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With