Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a Uri that is not absolute?

Tags:

c#

.net

uri

I am curious about the Uri property:

public bool IsAbsoluteUri { get; }

Is it ever possible for it to be false? It doesn't seem that I can create a Uri that is not absolute. The latter (uriTwo) throws:

var uriOne = new Uri( "http://stackoverflow.com/about" );
var uriTwo = new Uri( "/about" );

Same seems to be true with the builder. What am I missing?

like image 496
Joshua Ball Avatar asked Mar 15 '12 17:03

Joshua Ball


2 Answers

Yes. Try the following

var uri = new Uri("foo.jpg", UriKind.Relative);
Console.WriteLine(uri.IsAbsoluteUri); // prints false
like image 176
JaredPar Avatar answered Oct 19 '22 19:10

JaredPar


You need to use another constructor that takes a UriKind, for instance. The constructor that takes just a path assumes absolute kind.

like image 41
Jodrell Avatar answered Oct 19 '22 17:10

Jodrell