I have my class on C# on .NET, called after a request by an URI. I need to check if this URI contains some parameters or not.
For example :
http://www.website.com/page.aspx?ID=9 // must return YES
http://www.website.com/page.aspx?ID=9&Page=2 // must return YES
http://www.website.com/page.aspx // must return NO
is it possible? Of course I couldn't know the name for each parameters in the URI, so for a random querystring like :
http://www.website.com/page.aspx?RandomParameter=1
I need to return YES. Can I do it?
You have to allow for Request.QueryString
being null
as well (no parameters).
to return a string
:
return Request.QueryString != null && Request.QueryString.Count > 0 ? "YES" : "NO";
to return a bool
:
return Request.QueryString != null && Request.QueryString.Count > 0;
It has been quite a while since I have worked with these, but I believe something like the following should fit your needs:
Solution:
if(Request.QueryString != null && Request.QueryString.Count > 0)
{
return "YES";
}
else
{
return "NO";
}
Inline Solution (If this was all you needed to do):
return (Request.QueryString != null && Request.QueryString.Count > 0) ? "YES":"NO";
You can find more information on Request.QueryString here.
Try this method, If the requested page has any querystirng parameters defined then it will return true, otherwise it will return false
if (Request.QueryString.HasKeys())
{
Response.Write("The requested page URI has parameters");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With