C#获取url中参数键值对的方法

C#获取url中参数键值对的方法

 

 1 /// <summary>
 2 /// 遍历Url中的参数列表
 3 /// </summary>
 4 /// <returns>如:(?userName=keleyi&userType=1)</returns>
 5 public string GetUrlParam()
 6 {
 7     string urlParam = "";
 8     if (Request.QueryString.Count > 0)
 9     {
10         urlParam = "?";
11         NameValueCollection keyVals = Request.QueryString;
12         foreach (string key in keyVals.Keys)
13         {
14             urlParam += key + "=" + keyVals[key] + "&";
15         }
16         urlParam = urlParam.Substring(0, urlParam.LastIndexOf('&'));
17     }
18     return urlParam;
19 }

 

posted @ 2016-11-22 14:54  jeremy1888  阅读(5593)  评论(0编辑  收藏  举报