Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 242
THX-1138 Avatar asked Aug 11 '10 16:08

THX-1138


2 Answers

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

like image 152
Jon Skeet Avatar answered Oct 07 '22 14:10

Jon Skeet


You could try the UrlEncode method:

string encodedEmail = HttpUtility.UrlEncode(email);
like image 27
Darin Dimitrov Avatar answered Oct 07 '22 13:10

Darin Dimitrov