I have an error.aspx
page. If a user comes to that page then it will fetch the error path in page_load()
method URL using Request.QueryString["aspxerrorpath"]
and it works fine.
But if a user directly accesses that page the it will generate an exception because aspxerrorpath
is not there.
How can I check that aspxerrorpath
is there or not?
Check if a query string parameter existsThe URLSearchParams.has() method returns true if a parameter with a specified name exists.
The value of Request. QueryString(parameter) is an array of all of the values of parameter that occur in QUERY_STRING. You can determine the number of values of a parameter by calling Request. QueryString(parameter).
A POST request can include a query string, however normally it doesn't - a standard HTML form with a POST action will not normally include a query string for example.
You can just check for null
:
if(Request.QueryString["aspxerrorpath"]!=null) { //your code that depends on aspxerrorpath here }
Check for the value of the parameter:
// .NET < 4.0 if (string.IsNullOrEmpty(Request.QueryString["aspxerrorpath"])) { // not there! } // .NET >= 4.0 if (string.IsNullOrWhiteSpace(Request.QueryString["aspxerrorpath"])) { // not there! }
If it does not exist, the value will be null
, if it does exist, but has no value set it will be an empty string.
I believe the above will suit your needs better than just a test for null
, as an empty string is just as bad for your specific situation.
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