Search code examples
.neturlencodeurl-encoding

Escape + (plus) in URI


When user enters an e-mail on my web site, I send an e-mail verification e-mail that contains a link. Link looks something like:

http://mysite.com/[email protected]&token=12341234

This particular user's e-mail contains '+' (plus), so link looks like:

http://mysite.com/[email protected]&token=12341234

when link is clicked (at least in Firefox) plus is replaced with a space.

Question: What URL encoding function do I use in .net to escape the plus.

Note: Uri.EscapeUriString(email) leaves plus intact.


Solution

  • You can use Uri.EscapeDataString instead - I've just verified that that converts "Foo+Bar" into "Foo%2BBar".

    To be honest, I'd appreciate it if MS provided a little more guidance on the difference between these methods, as well as HttpUtility.UrlEncode (which isn't available on all platforms).