Handling Multiple QueryString Parameters With the Same Key in ASP.NET

C# Add comments

When you are processing an HTTP request in ASP.NET you can retrieve the user-provided query string parameters using the HttpRequest.QueryString property.  This property is an instance of the NameValueCollection class.

If the user has provided multiple parameters with the same key in the query string, HttpRequest.QueryString[key] will return all the values concatenated together with commas.  If you would rather process the values individually, use HttpRequest.QueryString.GetValues(key), which will return an array of all the provided values.

For example:

URL: http://example.com?a=1&a=2
HttpRequest.QueryString["a"] = "1,2"
HttpRequest.QueryString.GetValues("a") = { "1", "2" }

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in