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

方法如下:

/// <summary>

/// 遍历Url中的参数列表

/// </summary>

/// <returns>如:(?userName=keleyi&userType=1)</returns>

public string GetUrlParam()

{

    string urlParam = "";

    if (Request.QueryString.Count > 0)

    {

        urlParam = "?";

        NameValueCollection keyVals = Request.QueryString;

        foreach (string key in keyVals.Keys)

        {

            urlParam += key + "=" + keyVals[key] + "&";

        }

        urlParam = urlParam.Substring(0, urlParam.LastIndexOf('&'));

    }

    return urlParam;

}

 

你可能感兴趣的:(url)