How to encode the plus (+) symbol in a URL How to encode the plus (+) symbol in a URL asp.net asp.net

How to encode the plus (+) symbol in a URL


The + character has a special meaning in a URL => it means whitespace - . If you want to use the literal + sign, you need to URL encode it to %2b:

body=Hi+there%2bHello+there

Here's an example of how you could properly generate URLs in .NET:

var uriBuilder = new UriBuilder("https://mail.google.com/mail");var values = HttpUtility.ParseQueryString(string.Empty);values["view"] = "cm";values["tf"] = "0";values["to"] = "someemail@somedomain.com";values["su"] = "some subject";values["body"] = "Hi there+Hello there";uriBuilder.Query = values.ToString();Console.WriteLine(uriBuilder.ToString());

The result

https://mail.google.com:443/mail?view=cm&tf=0&to=someemail%40somedomain.com&su=some+subject&body=Hi+there%2bHello+there


Is you want a plus (+) symbol in the body you have to encode it as 2B.

For example: Try this


In order to encode + value using JavaScript, you can use encodeURIComponent function.

Example:

var url = "+11";var encoded_url = encodeURIComponent(url);console.log(encoded_url)