Reputation:
Is is possible to represent a URL with an empty path component with System.Uri?
Whenever I create
new Uri("http://example.com")
.Net (4) seems to insist on appending a trailing slash, thereby creating a different URL. In other words,
new Uri("http://example.com").ToString()
returns "http://example.com/" and
new Uri("http://example.com").Equals(new Uri("http://example.com/")) == true
Can this broken behavior (according to RFC 3986) be suppressed or do I have to roll my own class?
Update:
Looks like I missed this in section 6.2.3:
In general, a URI that uses the generic syntax for authority with an
empty path should be normalized to a path of "/".
The wording indicates this is optional however. So the question remains: can Uri be made to NOT do this?
Upvotes: 8
Views: 11809
Reputation: 13581
Since .NET 2.0 you can get the original string passed to the constructor via OriginalString
property. The original string is lost when Uri
object is serialized.
If this is not what you want, there is no help. Equals
and ToString
methods will always use the normalized version.
Upvotes: 2