Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Request.Params["key"] do?

Tags:

asp.net

Hi I want to know what Request.Params["key"] does? Where is it used?

like image 726
Nishant Kumar Avatar asked Aug 27 '10 14:08

Nishant Kumar


4 Answers

The key part is the indexer of the NameValueCollection. It can be either a string or numeric index into the collection.

If you use a string, it will return the value associated with the string, if you use an int, in will return the item that is in that index of the collection.

It combines all of the following NameValuePairs, in this order:

  • QueryString
  • Form
  • Cookies
  • ServerVariables

So, if you want to get the value of an object with the string key "myKey" that might be in any of the above (assuming you don't care which one), you would use:

var myValue = Request.Parameters["myKey"]; // C#
like image 65
Oded Avatar answered Oct 31 '22 06:10

Oded


Request.Params is a combination of the keys/values you'll find in Request.Querystring, Request.Form, Request.Cookies, Request.ServerVariables (in that order)

like image 30
David Hedlund Avatar answered Oct 31 '22 07:10

David Hedlund


It returns the value associated with "key".

I believe is looks among the QueryString parameters, the Form parameters, the cookies and the server varaibles looking for a match.

like image 26
James Curran Avatar answered Oct 31 '22 06:10

James Curran


Detailed in the MSDN article on Request.Params. The "key" is a string representing which item in the list you want.

As opposed to Request.Form or Request.QueryString, Request.Params can return you data from:

  1. Query-string parameters.
  2. Form fields.
  3. Cookies.
  4. Server variables

In that order.

like image 39
badbod99 Avatar answered Oct 31 '22 06:10

badbod99