简体   繁体   English

Request.QueryString 用法读取传递的数组

[英]Request.QueryString usage to read Passed array

I'm not able to read the array passed from the other page with Request.Querystring我无法使用 Request.Querystring 读取从其他页面传递的数组

//Label1.Text += FID[l]; //Checked the array and it is printing properly.

Response.Redirect("show.aspx?id=" + ID + "&name=" + NAME + "&fileid=" 
                  +FID+"&length="+j);


string fid=string.Empty;
if (!string.IsNullOrEmpty(Convert.ToString(Request.QueryString["fileid"].ToString())))
{
    fid = Request.QueryString["fileid"].ToString();

}

for (int l = 0; l < length; l++)
{

    Label1.Text += fid[l]; //Printing wrong array
}

Can anybody help me with this.任何人都可以帮我解决这个问题。

How can I use Global.aspx file to do this instead of parameter passing.如何使用Global.aspx文件而不是参数传递来执行此操作。

Your code makes no sense, first of all If that code is all in the same method then nothing after the Response.Redirect will run.您的代码毫无意义,首先如果该代码都在同一个方法中,那么 Response.Redirect 之后什么都不会运行。

Second assuming the Response.Redirect is not in the same method as the other code then其次假设 Response.Redirect 与其他代码的方法不同

if (!string.IsNullOrEmpty(Convert.ToString(Request.QueryString["fileid"].ToString())))

On the above line you are calling ToString() on something that is already a string and then converting it to a string.在上面的行中,您正在对已经是字符串的内容调用 ToString(),然后将其转换为字符串。 If Request.QueryString["fileid"] is null then this will throw a null reference exception.如果 Request.QueryString["fileid"] 是 null 那么这将抛出 null 引用异常。 You should do:你应该做:

if (!string.IsNullOrEmpty(Request.QueryString["fileid"]))

Third fid is a string, Label1.Text is a string.第三个fid是一个字符串,Label1.Text是一个字符串。 Why are you looping through the string char by char and then adding them onto the end Label1.Text.为什么要逐个字符地循环遍历字符串,然后将它们添加到末尾的 Label1.Text 中。

Finally fid will contain whatever is passed as the query string param "fileid", it can't contain anything else.最后,fid 将包含作为查询字符串参数“fileid”传递的任何内容,它不能包含其他任何内容。 If it has the "wrong" value then the "wrong" value is getting passed in the query string.如果它具有“错误”值,则“错误”值将在查询字符串中传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM