& in a QueryString

D

DaveF

I am looping threw the querySting with:
foreach (string name in Request.QueryString)

I have a problem with a '&' being in one of the values. How do I deal with
this?

page.asp?theVal=2&theVal2=aa&e overdue
--


David Fetrow
Helixpoint LLC.
http://www.helixpoint.com
(e-mail address removed)
 
J

John Toop

Hi Dave,
I think you should URLEncode the string before you build the hyperlink.
Basically "&" will create your ampersand ("&")

jt
 
S

Shiva

'&' in the URL should be urlencoded as %26

I am looping threw the querySting with:
foreach (string name in Request.QueryString)

I have a problem with a '&' being in one of the values. How do I deal with
this?

page.asp?theVal=2&theVal2=aa&e overdue
--


David Fetrow
Helixpoint LLC.
http://www.helixpoint.com
(e-mail address removed)
 
C

chanmmn

No... you & is legal. Check for other:

Example:

Dim uriString As String = "http://www.contoso.com/search"
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
' Create a new NameValueCollection instance to hold the QueryString parameters and values.
Dim myQueryStringCollection As New NameValueCollection()
Console.Write(("Enter the word(s), separated by space characters, to search for in " + uriString + ": "))
' Read user input phrase to search in uriString.
Dim searchPhrase As String = Console.ReadLine()
' Append necessary parameter/value pairs to the name/value container.
' as QueryString = "?q=Microsoft&btnG=Google+Search".
If searchPhrase.Length > 1 Then
'Assign the user-defined search phrase.
myQueryStringCollection.Add("q", searchPhrase)
' If error, default to search 'Microsoft'.
Else
myQueryStringCollection.Add("q", "Microsoft")
End If
' Assign auxilliary parameters required for the search.
myQueryStringCollection.Add("btnG", "Google" + ChrW(43) + "Search")
Console.WriteLine(("Searching " + uriString + " ......."))
' Attach QueryString to the WebClient.
myWebClient.QueryString = myQueryStringCollection
' Download the search results Web page into 'searchresult.htm' for inspection.
myWebClient.DownloadFile(uriString, "searchresult.htm")
Console.WriteLine((ControlChars.Cr + "Download of " + uriString + " was successful. Please see 'searchresult.htm' for results."))
 
M

Matt Berther

Hello chanmmn,

& is legal ... as an item delimiter.

If one of your items contains a &, it needs to be escaped (%26). You can
do this manually or with Server.UrlEncode(value). If you dont do this, then
the query string will be goofed up, because the delimiters are in the wrong
spot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top