System.Uri can't parse when password field contains a "#"

Posted by Andrew on Stack Overflow See other posts from Stack Overflow or by Andrew
Published on 2010-03-08T13:20:02Z Indexed on 2010/03/08 13:36 UTC
Read the original article Hit count: 668

Filed under:
|
|

The following code throws System.UriFormatException:

var uri = new UriBuilder("ftp://user:pass#[email protected]:21/fu/bar.zip");

System.UriFormatException: Invalid URI: A port was expected because of there is a colon (':') present but the port could not be parsed.

Removing the # symbol from the password field solves the issue.

  1. Is a # symbol a valid character to have in the password field?
  2. Is there a way to escape this?
  3. Is this a known bug in the parsing routine of the Uri class?
  4. How does one get around this - assuming you can't change the password? ;-)

Thanks, Andrew

© Stack Overflow or respective owner

Related posts about c#

Related posts about uri