I have a problem where I need to extract a query string parameter from a url. The parameter could be either "Territory"
or "territory"
or other upper/lower case variations of that word. Although the following works for the first two cases I wonder if there is a better way?
IDictionary<string, string> queryString = HtmlPage.Document.QueryString;
if (queryString.ContainsKey("territory"))
{
ish.SetDefaultRegion(int.Parse(queryString["territory"]));
// do something (the same something as below)
}
else if (queryString.ContainsKey("Territory"))
{
ish.SetDefaultRegion(int.Parse(queryString["Territory"]));
// do something (the same something as above)
}
I would prefer to insert the query string into the dictionary ignoring case (ie. if the user accidentally typed "TERRITORY"
this code would fail, so how can I just test that the word exists regardless of casing?
Request.QueryString["territory"]
is already case-insensitive. It doesn't matter whether it's in the URL as "Territory", "territory", "TeRrItOrY", etc. – Marozikif (Request.QueryString["TeRriToRy"] != null) {
– Marozik