Curtis
Curtis

Reputation: 103358

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?

Upvotes: 9

Views: 6516

Answers (1)

LukeH
LukeH

Reputation: 269388

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.

Upvotes: 19

Related Questions