1

i have question about query string in asp.net:

standart query string with query string parameter is "www.mysity.url?key1=value1&key2=value2", but i need only check has query string key or not...yes, one of the correct decisions: www.mysite.url?reset=true, but this excess syntax for me.

in markup i use something like "<a href='UrlHelper.GetResetUrl()'>Reset</a>", this method return "www.mysity.url?reset", but in user side markup i have "Reset"

1
  • You know that you can simple check your url if contains the "?reset" and that's all. Commented Sep 7, 2012 at 10:07

3 Answers 3

6

If you do not specify the name for a parameter it is taken as null.

Its value would be reset

So you would have to check it as follows:

if(Request.QueryString[null]=="reset")
{
    //Take some reset action
}
Sign up to request clarification or add additional context in comments.

1 Comment

this answer was useful for me, as the values are dynamic
1

a Quick and dirty solution is:

if(Request.Url.Query.Contains("?reset"))
{
    // ok we have a reset
}

Assuming that you have a standard reset call ask as: www.mysity.url?reset and the reset url not have other parameters. If you have you can simple check for the reset keyword.

This code HttpContext.Current.Request["reset"] is always return null, so the next best thing if you like to make it hard, is to manual analyze your keys after the url.

Comments

0

All code that handles querystring parameters should be case insensitive. Browsers (or parts of internet infrastructure?) may convert the case.

One way to check if reset parameter is present in querystring:

bool reset = Request.Url.Query.IndexOf("reset", StringComparison.CurrentCultureIgnoreCase) > -1;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.