Request() vs Request.QueryString()

I have recently started using Request("key") instead of Request.QueryString("key") to access my querystring values. However I have read that:

Gets the specified object from the System.Web.HttpRequest.Cookies,
System.Web.HttpRequest.Form, System.Web.HttpRequest.QueryString,
System.Web.HttpRequest.ServerVariables

Therefore, if I have a querystring key and cookie key which are the same, which value is returned?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

They’re checked in the following order:

  1. QueryString
  2. Form
  3. Cookies
  4. ServerVariables

The search is short-circuited, so as soon as a matching key is found the value is returned.

So, to answer your question, a matching QueryString item takes precedence over Cookies.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x