Super simple ApiController:
[ApiController]
[Route("[controller]")]
public class MyController : ControllerBase
{
[HttpPost]
public IActionResult DoStuff([FromHeader] string X-SomeValue)
{
return Ok();
}
}
This does not compile, as X-SomeValue is not a valid parameter name.
The easiest is just call it XSomeValue, but AFAIK best practise is use X-.
How can I use X-SomeValue in the header?
>Solution :
To use names that are not valid C# identifiers, you must specify the name explicitly like this:
[HttpPost]
public IActionResult DoStuff([FromHeader(Name = "X-SomeValue")] string xSomeValue)
{
return Ok();
}
More information on the FromHeader attribute’s Name property: