-1

I have to write this data in querystring:

  http://localhost:1256/4.market.ph.local/WEP/Add.cshtml?data=me+&+you

I got an error because of that symbol '&' i used.

Cheran Shunmugavel
  • 8,319
  • 1
  • 33
  • 40
David De Chavez
  • 57
  • 1
  • 15

2 Answers2

5

In c# you can use this:-

HttpUtility.UrlEncode("http://localhost:1256/4.market.ph.local/WEP/Add.cshtml?data=me+&+you");

HttpUtility is a part of System.Web and this will ensure an of the non permitted query string char are url Encoded.

Once you do this you will get something like this http%3a%2f%2flocalhost%3a1256%2f4.market.ph.local%2fWEP%2fAdd.cshtml%3fdata%3dme%2b%26%2byou

On the receiver just decode it back.

PSL
  • 123,204
  • 21
  • 253
  • 243
  • can i do it like this: string url = HttpUtility.UrlEncode("http://localhost:1256/4.market.ph.local/WEP/Add.cshtml?data=me+&+you").ToString();? – David De Chavez Apr 04 '13 at 03:56
  • Yes you can. What this just does is that it makes any string url safe... – PSL Apr 04 '13 at 03:59
3

Use urlencode($yourstring) or if you are hard coding it, use %26 to represent the ampersand.

Sounten
  • 192
  • 1
  • 2
  • 10