Other Query Parameter Information
While not directly part of this question, this additional information may also prove useful.
The Seperator Character
ASP.NET does not support query parameters seperated by ';'
which the W3C recommends that servers support as an alternative to '&'
.
Parameters Starting with "="
Query parameters that start with '='
, are considered to have a key, which would be string.Empty
. Do not confuse this with a key of null
. For example "/some-controller/some-action?=baz"
has one value whose key is string.Empty
and whose value is baz
.
More Than One "=" Character
If there is more than one '='
character, the key is everything before the first '='
, and the value is everythin after it.
For example "/some-controller/some-action?foo=bar=baz"
has one paramter with a key of "foo"
and a value of bar=baz
.
Annother example "/some-controller/some-action?eggs==spam"
has one parameter with a key of "eggs"
, and a value of "=spam"
.
Multiple Parameters of the Same Name
Multiple parameters of the same name are also supported, as hinted at in my other answer.
For example if the URL is "/some-controller/some-action?foo=bar&foo=baz"
, then the result of Request.QueryString["foo"]
is `"bar,baz".
If you want each string seperately, use Response.QueryString.GetValues("foo")
, which returns an array of strings.
Example
The The following highly implasuble URL would be considered to have six parameters:
"/some-controller/some-action?=baz&foo=bar&edit&spam=eggs=ham&==&"
They are:
+--------------+--------------+
| Key | Value |
+--------------+--------------+
| string.Empty | "baz" |
| "foo" | "bar" |
| null | "edit" |
| "spam" | "eggs=ham" |
| string.Empty | "=" |
| null | string.Empty |
+--------------+--------------+