Is there a way to get all the querystring name/value pairs into a collection?
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]);}
Well, Request.QueryString
already IS a collection. Specifically, it's a NameValueCollection
. If your code is running in ASP.NET, that's all you need.
So to answer your question: Yes, there is.
You can use LINQ to create a List of anonymous objects that you can access within an array:
var qsArray = Request.QueryString.AllKeys .Select(key => new { Name=key.ToString(), Value=Request.QueryString[key.ToString()]}) .ToArray();