Empty QueryString parameter
You get null because the foo
parameter doesn't have a value with it.
...What's the problem exactly?
If you still want to check for its existence (although it lacks a value), try something like this:
bool doesFooExist = Request.Url.AbsoluteUri.IndexOf("foo=") >= 0 ? true : false;
Request.ServerVariables["QUERY_STRING"]
will return the query string, complete, as a string. Then search it using a Regex or IndexOf
You can use null
as the key for the NameValueCollection
and it will give you a comma-delimited list of parameter names that don't have values.
For http://example.com?bar=3&foo
you would use Request.QueryString[null]
and it would retrieve foo
.
If you have more than one parameter name without a value, it will give you a value that is comma-delimited.
For http://example.com?bar=3&foo&test
you would get foo,test
as a value back.
Update:
You can actually use Request.QueryString.GetValues(null)
to get the parameter names that don't have values.