Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string to proper URI format?

Tags:

html

c#

asp.net

Is there any easy way to convert email address string into proper URI format?

Input:

http://mywebsite.com/validate_email/3DE4ED727750215D957F8A1E4B117C38E7250C33/[email protected]  

Output should be:

http://mywebsite.com/validate_email/3DE4ED727750215D957F8A1E4B117C38E7250C33/myemail%40yahoo.com  

If I didn't do the output, I get an error response like

An Error Was Encountered
The URI you submitted has disallowed characters.

Thanks in advance !

like image 812
fiberOptics Avatar asked Jan 03 '12 08:01

fiberOptics


1 Answers

Description

You have to extract your QueryString from the url, encode them and build the new url.

Sample

string url = "http://mywebsite.com/validate_email/3DE4ED727750215D957F8A1E4B117C38E7250C33/[email protected]";
int index = url.LastIndexOf("/");

string queryString = url.Substring(index + 1, url.Length - (index + 1));
url = url.Substring(0, index) + "/" + HttpUtility.UrlEncode(queryString);

// url is now
// http://mywebsite.com/validate_email/3DE4ED727750215D957F8A1E4B117C38E7250C33/myemail%40yahoo.com

More Information

  • String.LastIndexOf Method
  • String.Substring Method
  • HttpUtility.UrlEncode Method
like image 196
dknaack Avatar answered Sep 21 '22 13:09

dknaack