4

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;
}

1 Answer 1

7

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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.