Assingning string variable contains URL with '&' symbols

82 views Asked by At

while Assingning string variable contains URL with '&' symbols vai query string it splits string at '&' and the string after that is gone like below

query string contains strins like this "http://maps.googleapis.com/maps/api/staticmap?center=34.0833869772674,74.7986488044262&zoom=21&size=550x450&maptype=roadmap&sensor=true"

but when i assign this like below

string str = Request.QueryString["imgName"].ToString();

it contains "http://maps.googleapis.com/maps/api/staticmap?center=34.0833869772674,74.7986488044262" that part only

2

There are 2 answers

0
Sourav 'Abhi' Mitra On BEST ANSWER

From MSDN:

The QueryString collection retrieves the values of the variables in the HTTP query string. The HTTP query string is specified by the values following the question mark (?).

In your case the QueryString collection would contain five members: center, zoom, size, maptype, sensor. Retrieve them like so:

Request.QueryString("center")

Similarly for the other variables as well.

0
har07 On

You can use Server.UrlEncode() method to produce save string for use in url. For example :

string queryString = "http://maps.googleapis.com/maps/api/staticmap?center=34.0833869772674,74.7986488044262&zoom=21&size=550x450&maptype=roadmap&sensor=true";
Response.Redirect("http://www.mysite.com/?imgName=" 
                    + Server.UrlEncode(queryString));