smwikipedia
smwikipedia

Reputation: 64205

How to access query string, headers and other information in a ASP.NET Web API action method?

I am writing a Web API to handle some request. The request url schema is fixed. I cannot modify it. So I have to collect all the necessary info from places like:

How can I access all these locations within a Web API action method?

Upvotes: 0

Views: 87

Answers (1)

Raja Nadar
Raja Nadar

Reputation: 9489

The Query String and Post Data information can be received as Web API Method parameters (preferred way, since Web API will do the necessary binding for you) Use the FromBody or FromUri attributes on the method parameters)

OR

you could access it using the old fashioned way of Request object. you have access to the http request using the Request object in your Web API Action method. you can get all the information using..

Request.QueryString
Request.Form["name"]
Request.Cookies
Request.Headers

Upvotes: 2

Related Questions