Handling Multiple QueryString Parameters With the Same Key in ASP.NET
ASP.NET asp.net csharp
Published: 2009-09-23
Handling Multiple QueryString Parameters With the Same Key in ASP.NET

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

1
2
HttpRequest.QueryString["a"] = "1,2"
HttpRequest.QueryString.GetValues("a") = ["1", "2"]