如何获得与他们在asp.net C#中值的所有URL参数列表? [英] How to get a list of all the url parameters with their values in asp.net c#?

查看:124
本文介绍了如何获得与他们在asp.net C#中值的所有URL参数列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的asp.net C#中的解决方案,我想所有的URL参数,其中关键是参数名称的字典和值为参数值。我怎样才能做到这一点?

In my asp.net c# solution, I want to get a dictionary of all the url parameters, where the key is the parameter name and the value is the parameter value. How can I do this?

感谢。

推荐答案

您需要HttpUtility.ParseQueryString

You need HttpUtility.ParseQueryString

NameValueCollection qscollection = HttpUtility.ParseQueryString(querystring);

您可以用这个来获取查询字符串值本身:

you can use this to get the querystring value itself:

 Request.Url.Query

要放一起

NameValueCollection qscollection = HttpUtility.ParseQueryString(Request.Url.Query);



在的http://msdn.microsoft.com/en-us/library/ms150046.aspx

较硬手工方式不使用内建的方法是这样的:

The harder manual way without using the builtin method is this:

NameValueCollection queryParameters = new NameValueCollection();
string[] querySegments = queryString.Split('&');
foreach(string segment in querySegments)
{
   string[] parts = segment.Split('=');
   if (parts.Length > 0)
   {
      string key = parts[0].Trim(new char[] { '?', ' ' });
      string val = parts[1].Trim();

      queryParameters.Add(key, val);
   }
}

这篇关于如何获得与他们在asp.net C#中值的所有URL参数列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆