1

I am passing a query string between asp.net pages in a VB.net application. I recieve the string by doing the following:

Dim pagename_username As String = Request.QueryString("field1")

The query string made up of a URL and a user_id, and is sent via JavaScript.

The string is then split in the VB page, by doing the following:

  Dim parts As String() = pagename_username.Split(New String() {"|"}, StringSplitOptions.None)
            Dim pagename As String = parts(0)
            Dim username As String = parts(1)

This works fine for the following query string:

field1=http://**********/default.aspx|1

But gives an outside the bounds of the array error for the following query string:

field1=http://**********/docstore/browse.aspx?docstoreid=0&docstoretypeid=2|1

My suspicion is that the second string is too long??

If so, how can I solve it?

If not, what is the problem?

Steven Doggart
  • 43,358
  • 8
  • 68
  • 105
Alex
  • 3,730
  • 9
  • 43
  • 94
  • 2
    You should encode the url for the query string: http://stackoverflow.com/questions/829080/how-to-build-a-query-string-for-a-url-in-c and http://stackoverflow.com/questions/10431107/how-do-i-send-a-url-with-query-strings-as-a-query-string – Tim Schmelter Jan 22 '15 at 12:05
  • 2
    With the code you provided the issue can't be reproduced. Are you sure the string is exactly `field1=http://**********/docstore/browse.aspx?docstoreid=0&docstoretypeid=2|1`? It sounds like there's no `|` character in the string that throws the exception at all. – sloth Jan 22 '15 at 12:37
  • @sloth I have fixed it now, I split the username and URL into 2 parameters and passed them as 2 query strings. I also encoded the URL as suggested by Tim Schmelter. I think the problem was the & sign – Alex Jan 22 '15 at 12:57

1 Answers1

3

In a query string, you separate the parameters by the '&' sign. For example, the following query string has two parameters:

www.someurl.com?param1=1&param2=2

In your case:

field1=http://**********/docstore/browse.aspx?docstoreid=0&docstoretypeid=2|1

Notice the delimiter (i.e. '|') is in the second query string parameter, which is docstoretypeid, and not included in the value of field1. Therefore, when you call Request.QueryString("field1"), you aren't getting the full string that contains the pipe delimiter. That's why, your split fails and you are getting the exception.

Steven Doggart
  • 43,358
  • 8
  • 68
  • 105
Y.S
  • 1,860
  • 3
  • 17
  • 30