2

I am migrating from a Java Jax-Rs API into ASP.NET. I have custom header params that I pass into the API.

enter image description here

enter image description here

I couldn't find the way to do the same in ASP.NET.

This is what I have so far:

  [HttpPost]
  public String login()
  {
     return "works";       
  }

I searched in every tutorial I found and couldn't find any mention to this.

1 Answer 1

6

ASP.NET Core does support Model Binding from the header, so, to get similar to your action listed you could use.

  [HttpPost]
  public String login([FromHeader(Name="usuario")] string usuario, [FromHeader(Name="pass")] string pass))
  {
     return "works";       
  }

You could then interact with the properties as desired.

Sign up to request clarification or add additional context in comments.

2 Comments

Still surprised about how easy it was to do (and how common) and how hard was to find documentation.
Once you get used to some of the concepts you can dig into the documentation, but it isn't always as easy as you would hope. I run into this a lot and it is why I often blog about the "fun" things that I've read in documentation

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.