问题
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