Is there a way to get all the querystring name/value pairs into a collection?

Blankman picture Blankman · Mar 3, 2010 · Viewed 75.5k times · Source

Is there a way to get all the querystring name/value pairs into a collection?

I'm looking for a built in way in .net, if not I can just split on the & and load a collection.

Answer

Andrew Hare picture Andrew Hare · Mar 3, 2010

Yes, use the HttpRequest.QueryString collection:

Gets the collection of HTTP query string variables.

You can use it like this:

foreach (String key in Request.QueryString.AllKeys)
{
    Response.Write("Key: " + key + " Value: " + Request.QueryString[key]);
}