如何读取ASP.NET原始URL的查询字符串参数?

我有一个变量

string rawURL = HttpContext.Current.Request.RawUrl; 

如何读取此URL的查询字符串参数?

这可能就是你所追求的

  Uri theRealURL = new Uri(HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.RawUrl); string yourValue= HttpUtility.ParseQueryString(theRealURL.Query).Get("yourParm"); 

无需通过RawUrlRequest对象已经包含使用Request.QueryString属性的已解析版本。

这是一个索引的NameValueCollection

Request对象上有Params属性,可以让您轻松完成。 您不必自己解析它。

试试这个:

string rawURL = HttpContext.Current.Request.ServerVariables["query_string"];

这将解决您的问题…..

 string strReq = ""; strReq = HttpContext.Current.Request.RawUrl; strReq = strReq.Substring(strReq.IndexOf('?') + 1);