Question

While poking around with the Uri class answering another question, I found something that seems strange to me:

Consider these two Uris:

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

They differ only by their scheme. All other elements of the supplied identifiers are the same.

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

/ 
abc/ 
def/ 
c 

...but a different output for u2?

/ 
abc%2fdef/ 
c 

Why is the the parsing behaviour different for different schemes?

Était-ce utile?

La solution

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

UriParser.Register(new HttpStyleParser(), "foobar", 33);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top