0

I'm using AntiXssEncoder.UrlEncode to encode values in query string parameters. Spaces are being encoded as %20, but I want to use a plus sign instead.

Is there a better way to do this than calling .Replace("%20", "+") on the resulting string?

  • Why? The %20 is the standard url encoding... Any UrlDecode will also convert it back to a ' '. Also the URL encode for + is %2B. – Austin T French Jul 01 '16 at 13:46
  • @AustinFrench This is what my company prefers, and [if I understand correctly a plus sign is an acceptable standard too.](http://stackoverflow.com/questions/1211229/in-a-url-should-spaces-be-encoded-using-20-or/1211261#1211261) – The Insoluble Lurnip Jul 01 '16 at 13:49
  • That is for query strings... But not all decoders handle it correctly. If its for an API that or web service that relies on interoperability %20 is still better. If all best practices are or everything is tightly controlled, then regex or string replace would work. as AntiXssEncoder doesn't seem to have a raw mode or something similar. – Austin T French Jul 01 '16 at 14:02

1 Answers1

0

You can easily do this by creating your own HtmlHelper class.

Something as simple as this would suffice:

public static class CustomHtmlHelpers 
{
   public static string UrlEncode(string url)
   {
       return url.Replace(" ", "+");
   }
}

And then just use it like this:

CustomHtmlHelpers.UrlEncode("bla bla bla");
Joakim Hansson
  • 544
  • 3
  • 15