C# 如何读取 ASP.NET 原始 URL 的查询字符串参数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11676975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to read the query string params of a ASP.NET raw URL?
提问by GilliVilla
I have a variable
我有一个变量
string rawURL = HttpContext.Current.Request.RawUrl;
How do I read the query string parameters for this url?
如何读取此 url 的查询字符串参数?
采纳答案by Shankar R10N
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");
回答by Oded
No need to go through the RawUrl- the Requestobject already contains a parsed version, using the Request.QueryStringproperty.
无需通过RawUrl-Request对象已经包含使用该Request.QueryString属性的解析版本。
This is an indexed NameValueCollection.
这是一个索引的NameValueCollection.
回答by Piotr Perak
There is Params property on Request object that will let you do it easily. You don't have to parse it yourself.
Request 对象上有 Params 属性,可以让您轻松完成。您不必自己解析它。
回答by Rafael Massami
Try this:
尝试这个:
string rawURL = HttpContext.Current.Request.ServerVariables["query_string"];
string rawURL = HttpContext.Current.Request.ServerVariables["query_string"];
回答by Ganeswar.B
This will solve your problem.....
这将解决您的问题......
string strReq = "";
strReq = HttpContext.Current.Request.RawUrl;
strReq = strReq.Substring(strReq.IndexOf('?') + 1);

