获得C#ASP.NET全面查询字符串 [英] Get full query string in C# ASP.NET
问题描述
作为PHP程序员,我习惯了使用$ _GET来检索HTTP查询字符串...如果我需要整个字符串,那里有办法做到这一点负载。
As a PHP programmer I'm used to using $_GET to retrieve the HTTP query string... and if I need the whole string, theres loads of ways to do it.
在ASP不过,我似乎无法得到查询。
In ASP however, I can't seem to get the query.
下面是code为news.aspx(嵌入一些HTML):
Here is the code for news.aspx (embedded in some HTML):
<%
string URL = "http://www.example.com/rendernews.php?"+Request.Querystring;
System.Net.WebClient wc = new System.Net.WebClient();
string data = wc.DownloadString(URL);
Response.Output.Write(data);
%>
我从获取远程服务器的PHP脚本的输出,这完美的作品没有的Request.QueryString。
I am fetching a PHP script's output from a remote server, and this works perfectly without the Request.Querystring.
问题是,我试图让第一线的全部查询字符串:的Request.QueryString。我得到一个错误的对象引用未设置为一个对象的实例,这基本上意味着的Request.QueryString不存在。
The issue is that I'm trying to get the full query string on the first line: Request.Querystring. I am getting an error "Object reference not set to an instance of an object" which basically means that Request.Querystring doesn't exist.
任何想法的问题是什么吗?我怎样才能得到查询字符串,所以当Index.aspx的被称为像 http://test.com/news.aspx?id = 2 我的脚本获取 http://www.example.com/rendernews.php?id=2
Any idea what the problem is here? How can I get that query string so when index.aspx is called like http://test.com/news.aspx?id=2 my script fetches http://www.example.com/rendernews.php?id=2
在此先感谢
推荐答案
尝试<一个href=\"https://msdn.microsoft.com/en-us/library/system.uri.query(v=vs.110).aspx\"><$c$c>Request.Url.Query$c$c>如果你想要的原始查询字符串为一个字符串。
Try Request.Url.Query
if you want the raw querystring as a string.
这篇关于获得C#ASP.NET全面查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!