Why does Uri behave differently for different designs?

While talking to the Uri class, answering another question, I found something that seemed strange to me:

Consider these two Uris:

var u1 = new Uri("http://ab:33/abc%2fdef/c?d=f"); var u2 = new Uri("foobar://ab:33/abc%2fdef/c?d=f"); 

They differ only in their scheme. All other elements of the identifiers provided are the same.

So why, when I Segments property of these Uri instances, I see the following output for u1 :

  / 
 abc / 
 def / 
 c 

... but another conclusion for u2 ?

  / 
 abc% 2fdef / 
 c 

Why is parsing behavior different for different schemas?

+4
source share
1 answer

The Uri Class uses different parsers for different URI schemes. For example, for the http and https URI, it uses the HttpStyleUriParser , while for the ftp URI it uses the FtpStyleUriParser , etc. URIs with unknown schemes are handled by GenericUriParser . You can register new schemes using the UriParser.Register Method .

 UriParser.Register(new HttpStyleParser(), "foobar", 33); 
+5
source

All Articles