【发布时间】:2020-01-07 19:11:54
【问题描述】:
通常我可以使用httpcontext读取参数inurl,但我想知道url中是否有多个查询参数我可以将它们作为键值获取吗?
网址:localhost:3034/?CustomerID=12345&RoleName=Student
string customerID = this.HttpContext.Request["CustomerID"];
string roleName= this.HttpContext.Request["RoleName"];
我是否有机会将它作为键值保存,而不是像上面那样一一阅读并在项目的任何地方使用它?
提前致谢
【问题讨论】:
-
您是否希望它作为“键值”,因为您想迭代所有参数?它们目前是键值,因为您输入 CustomerId 的键并取回值。
-
Item[String] 集合是 QueryString、Form、Cookies 和 ServerVariables 集合的组合。我认为 OP 只是在寻找 QueryString 集合,奇怪的是,它似乎不像其他人那样暴露为 NameValueCollection。
-
@AlwaysLearning 实际上是这样。它是 QueryString 属性。
-
@Xipooo ... 这是一个字符串属性,而不是 NameValueCollection。
-
@AlwaysLearning 我向你保证是 :) docs.microsoft.com/en-us/dotnet/api/…
标签: c# httpcontext url-parameters