[SOLVED] Passing array into query string

Issue

I need to send array as query parameter, I do it like this

StringBuilder Ids = new StringBuilder();
for (int i = 0; i < array.Count; i++)
{
    Ids.Append(String.Format("&id[{0}]={1}", i, items[i].ID));
}
                    
ifrDocuments.Attributes.Add("src", "Download.aspx?arrayCount=" + array.Count + Ids);

After this I have string:

Download.aspx?arrayCount=8&id[0]=106066&id[1]=106065&id[2]=106007&id[3]=105284&id[4]=105283&id[5]=105235&id[6]=105070&id[7]=103671

It can contain 100 elements and in this case I’m getting error:

enter image description here

Maybe I can do it in another way? Not by sending it inside query qtring.

Solution

There is a limit on URL length on multiple levels (browsers, proxy servers, etc). You can change maxQueryString (*1) but I would not recommend it if you expect real users to use your system.

It looks like downloads.aspx is your page. Put all those ids in temporary storage – (cache or database) and pass the key to this new entity in the request

*1: https://blog.elmah.io/fix-max-url-and-query-string-length-with-web-config-and-iis/

Answered By – st78

Answer Checked By – Robin (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *