Daniel Miller Daniel Miller - 1 year ago 131
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!

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download