How to read the query string params of a ASP.NET raw URL?

混江龙づ霸主 提交于 2019-12-20 11:37:07

问题


I have a variable

string rawURL = HttpContext.Current.Request.RawUrl;

How do I read the query string parameters for this url?


回答1:


This is probably what you're after

  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"); 



回答2:


No need to go through the RawUrl - the Request object already contains a parsed version, using the Request.QueryString property.

This is an indexed NameValueCollection.




回答3:


Try this:

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




回答4:


There is Params property on Request object that will let you do it easily. You don't have to parse it yourself.




回答5:


This will solve your problem.....

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


来源:https://stackoverflow.com/questions/11676975/how-to-read-the-query-string-params-of-a-asp-net-raw-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!