Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#获取uri参数_C#_Url - Fatal编程技术网

C#获取uri参数

C#获取uri参数,c#,url,C#,Url,我想用报表文件夹(报表项目1)获取部分url。 我尝试了HttpContext.Current.Request.Url.Segments,但是这个返回数组包含以下项:“\”、“ReportServer”、“Reserved.ReportServer” 如何使用Report Project1获取零件?这是正确的解决方案: HttpContext.Current.Request.QueryString.Get(0) 这是正确的解决方案: HttpContext.Current.Request.Qu

我想用报表文件夹(报表项目1)获取部分url。 我尝试了
HttpContext.Current.Request.Url.Segments
,但是这个返回数组包含以下项:“\”、“ReportServer”、“Reserved.ReportServer”


如何使用Report Project1获取零件?

这是正确的解决方案:

HttpContext.Current.Request.QueryString.Get(0)

这是正确的解决方案:

HttpContext.Current.Request.QueryString.Get(0)

由于此请求中的查询不是标准的,即第一个参数没有变量名,只有文件夹路径,因此无法可靠地获取URI查询参数。下面的代码将提供您想要的功能,但是使用简单的String.split()查找文件夹的regex可能更可靠

Uri temp = new Uri("http://localhost/ReportServer/Reserved.ReportServer?/Report+Project1&rs:Command=ListChildren");
string query = temp.Query;
var folder = HttpUtility.ParseQueryString(query).Get(null);

如果Get方法中有空值,您应该真正提供变量名,在您的示例中,放入
rs:Command
将返回该参数的值。

,因为此请求中的查询不是标准的,即第一个参数没有变量名,只有文件夹路径,无法以可靠的方式获取URI查询参数。下面的代码将提供您想要的功能,但是使用简单的String.split()查找文件夹的regex可能更可靠

Uri temp = new Uri("http://localhost/ReportServer/Reserved.ReportServer?/Report+Project1&rs:Command=ListChildren");
string query = temp.Query;
var folder = HttpUtility.ParseQueryString(query).Get(null);

如果Get方法中有空值,您应该提供变量名,在您的示例中,
rs:Command
将返回该参数的值。

这是查询字符串参数。。。尝试此
HttpContext.Current.Request.QueryString
谢谢,但QueryString中的数组是包含两项的allkey:null和rs:Command,报表项目1不在此数组中,您需要正确构建url,即:…ReportServer?/&Report=Project1&rs=ListChildren或rs应该是什么。然后通过ctx.Request.Params.Get(“rs”)或(“Report”)或QueryString访问它,或者尝试删除
之后的
/
。这可能是问题所在。这是查询字符串参数。。。尝试此
HttpContext.Current.Request.QueryString
谢谢,但QueryString中的数组是包含两项的allkey:null和rs:Command,报表项目1不在此数组中,您需要正确构建url,即:…ReportServer?/&Report=Project1&rs=ListChildren或rs应该是什么。然后通过ctx.Request.Params.Get(“rs”)或(“Report”)或QueryString访问它,或者尝试删除
之后的
/
。这可能是问题所在。但请注意,参数必须位于第一位everYes,此url位于Reporting Server中,在适合的情况下不会发生更改:),但请注意,参数必须位于第一位everYes,此url位于Reporting Server中,在适合的情况下不会发生更改:)