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.

推荐答案

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]);
}

Asp.net相关问答推荐

如何正确配置 IHttpModule?

如何使用 executeReader() 方法仅检索一个单元格的值

在 Sessions 中存储自定义对象

ASP.NET web api 无法获取 application/x-www-form-urlencoded HTTP POST

模型项的类型为 CookMeIndexViewModel,但需要类型为 IEnumerable 的模型项

如何使用 jQuery 设置 outerHTML

Web api 不支持 POST 方法

没有身份的 ASP.NET Core 2.0 承载身份验证

文本框的输入按键触发事件

FluentValidation 使用数据库的唯一名称验证

Request.Params 和 Request.Form 什么时候不同?

Web Api 请求内容在操作过滤器中为空

Devexpress 或 Telerik Controls 比较

问题映射 HttpHandler --> HTTP Error 404 Not Found

使用 VirtualPathProvider 从 DLL 加载 ASP.NET MVC 视图

路由模板分隔符/不能连续出现 - 属性路由问题

如何在 ASP.Net MVC 3 中返回 HttpNotFound() 的视图?

将 MemoryStream 写入响应对象

解耦 ASP.NET MVC 5 标识以允许实现分层应用程序

Sys.WebForms.PageRequestManagerServerErrorException:处理服务器上的请求时发生未知错误.