Home > DeveloperSection > Forums > Passing a parameter from request header to the API controller action method
john rob

Total Post:108

Points:756
Posted on    November-17-2014 11:34 PM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 559  View(s)
Rate this:

I am using WEB API 2.0 for REST Service development and I need to pass a parameter from request header to the API controller action method. How can I?

 

By default API controller is reading the parameters from request body. How can I make it read parameter from request header?

 

[HttpPost]

[Route("abc")]

public IHttpActionResult abcMethod(string s)

{

   //some code

}

I want the above abcMethod to read it's parameter from request header.

Pls suggest.



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    November-17-2014 11:45 PM

Hi John, 
try this:

IEnumerable<string> headerValues = request.Headers.GetValues("MyCustomID");

var id = headerValues.FirstOrDefault();


Don't want to miss updates? Please click the below button!

Follow MindStick