Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Uri problem with mail-address as authentication
 

Uri problem with mail-address as authentication

Hi

I have a problem with using Uri:s with a mail-address as UserName.
Take a look at this code:

UriBuilder uriBuild = new UriBuilder();

uriBuild.Scheme = "ftp";
uriBuild.Host = "ftp.host.com";
uriBuild.Path = "path1/path2";
uriBuild.UserName = "name@mail.address.com";
uriBuild.Password = "password";

Console.WriteLine(uriBuild.ToString()); // Output is ftp://name@mail.address.com:password@ftp.host.com/path1/path2
UriBuilder uriBuild2 = new UriBuilder(uriBuild.ToString());

Last line throw an exception: Invalid URI: A port was expected because of there is a colon (':') present but the port could not be parsed
And when using it in WebClient.UploadFile also throws same expression.

The problem is the @ in the mail-address, if using any username without it everything works.
UriBuilder threats the first @ in the Uri as the separation between password and host...but it's not, the second @ is.
It doesn't matter if I also provide Port number.
Alagazam  Thursday, June 18, 2009 7:55 AM

Hi Alagazam

From my experience, you need to use the hex format of a special character if the character is contained in the username of the ftp path. The character @ need to be replaced with %40. So you need to change the path ftp://name@mail.address.com:password@ftp.host.com/path1/path2

to ftp://name%40mail.address.com:password@ftp.host.com/path1/path2.

Let me know if this helps.

Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, June 19, 2009 11:51 AM

Hi Alagazam

From my experience, you need to use the hex format of a special character if the character is contained in the username of the ftp path. The character @ need to be replaced with %40. So you need to change the path ftp://name@mail.address.com:password@ftp.host.com/path1/path2

to ftp://name%40mail.address.com:password@ftp.host.com/path1/path2.

Let me know if this helps.

Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, June 19, 2009 11:51 AM

You can use google to search for other answers

Custom Search

More Threads

• serching listview
• Embedded control problem
• Help needed for WinForm Application
• Cannot copy usercontrol at design-time
• Show HTML page in PrintPreviewDialog or PrintPreviewControl Control
• Editable Panel within UserControl
• Lost tool bars while developing a Form in Access 2003
• Designer Generated Code: SizeF
• Problem Using Visual basic 2008 (Application Not Working in Other PC)
• My Data Binding Solution for a "Browse for Drive" Dialog Box