Daniel Miller Daniel Miller - 8 months ago 60
C# Question

Check if non-valued query string exists in url with C#

I've seen a couple examples of how to check if a query string exists in a url with C#:



But how would I check a string without a parameter? I just need to see if it exists.


if(Request.QueryString["query"] != null) //why is this always null?

I know there's probably a simple answer and I'll feel dumb, but I haven't been able to find it yet. Thanks!


If query was included as a parameter, but no value was specified, then the value of query will be null but it will still exist in Request.QueryString.AllKeys.

If query was not included, it won't exist in Request.QueryString.AllKeys at all.