-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,119
  • 1
  • 31
  • 39

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
  • 122,084
  • 19
  • 250
  • 241
  • 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