-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.

5
  • you need to escape it Commented Apr 4, 2013 at 3:44
  • 1
    in php you would need to use urlencode or use %26 for & Commented Apr 4, 2013 at 3:45
  • but i have to include it for future display Commented Apr 4, 2013 at 3:45
  • 1
    you can't use & because its a delimiter for splitting up variables eg: foo=sdfs&bar=sdf otherwise you wouldn't know what the individual variables were Commented Apr 4, 2013 at 3:47
  • 1
    I've changed title of you post - feel free to revert (please try keep thank you note out - accept/upvote answers as thanks intead) Commented Apr 4, 2013 at 3:54

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

can i do it like this: string url = HttpUtility.UrlEncode("localhost:1256/4.market.ph.local/WEP/…;?
Yes you can. What this just does is that it makes any string url safe...
3

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

2 Comments

thanks. may be i'll just replace ampersand with %26 because im using C# language. ty for the info.
If it's C#, you can use Server.HtmlEncode(string s)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.