c# - 如何将 url 参数保留为键值
问题描述
通常我可以使用 httpcontext 读取参数 inurl 但我想知道 url 中是否有多个查询参数我可以将它们作为键值获取吗?
url: localhost:3034/?CustomerID=12345&RoleName=Student
string customerID = this.HttpContext.Request["CustomerID"];
string roleName= this.HttpContext.Request["RoleName"];
我是否有机会将它作为键值来保存,而不是像上面那样一一阅读并在项目的任何地方使用它?
提前致谢
解决方案
您可以直接访问 Response 对象的 Headers 属性以获取标头或 QueryString 属性以获取查询参数。他们都已经是一个集合:
NameValueCollection headers = this.HttpContext.Request.Headers;
NameValueCollection queryParams = this.HttpContext.Request.QueryString;
推荐阅读
- jquery - 我可以在加载 Kendo Grid 时有条件地将行显示为可编辑吗?
- ruby-on-rails - 这个版本的 Ruby 在 Heroku-18 上不可用
- swift - 自定义 MKAnnotationView 想要再次被点击
- omnet++ - 模块 ipv4NetworkConfigurator 中的错误,找不到配置器模块“ipv4NetworkConfigurator”
- laravel - 我尝试在组件 vue 中安装组件
- java - Android 应用程序具有外部 SD 卡写入权限,但我仍然无法修改文件
- flutter - 无需每次调用 `of(context)` 的本地化
- java - 有没有办法在junit和黄瓜中使用surefire-plugin报告?
- python - 我的 wx.OnPaint() 函数不会在 wx 主循环中不断调用
- perl - 从 rhel6 升级到 rhel8 后 Perl 代码崩溃