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?
Form, the Web server parses the HTTP request body and returns the specified data. If your application requires unparsed data from the form, you can access it by calling Request. Form without any parameters. The QueryString collection retrieves the values of the variables in the HTTP query string.
The value of Request. QueryString(parameter) is an array of all of the values of parameter that occur in QUERY_STRING. You can determine the number of values of a parameter by calling Request. QueryString(parameter).
A Query String collection is a parsed version of the QUERY_STRING variable in the Server Variables collection. It enable us to retrieve the QUERY_STRING variable by name. When we use parameters with Request. QueryString, the server parses the parameters sent to the request and returns the effective or specified data.
Generally, the query string is one of client-side state management techniques in ASP.NET in which query string stores values in URL that are visible to Users. We mostly use query strings to pass data from one page to another page in asp.net mvc. In asp.net mvc routing has support for query strings in RouteConfig.
They're checked in the following order:
QueryString
Form
Cookies
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With