When I have a url like:
http://www.mysite.com/?MyTest=
MyTest shows up as a key in the querystring of the request object.
If I remove the = sign like:
It no longer shows up in the querystring keys (or AllKeys if you prefer).
How can I determine whether this key exists or not?
I believe you can do
Request.QueryString[null]
orRequest.QueryString.GetValues(null)
.Without the equal sign MyTest is no longer a key, but a key-less value, you use
null
to get those. To check for both cases do this:You shoul use
ToString()
functionThis is quite odd behaviour, without the = sign the QueryString object returned by the Request has a Count of 1 with a value of MyTest and a key of null.
You could test the QueryString to see if it contains the value you are expecting:
Edit: this answer gives a bit more explanation as to what is going on with keyless parameters (scroll past the accepted answer).