If I create Uri using UriBuilder as follows:
var rootUrl = new UriBuilder("http", "example.com", 50000).Uri;
then AbsoluteUri of rootUrl always contains a rootUrl slash like this:
http:
I would like to create a Uri object without a trailing slash, but that seems impossible.
My workaround is to save it as a string instead and do something ugly:
var rootUrl = new UriBuilder("http", "example.com", 50000).Uri.ToString().TrimEnd('/');
I heard people say that without a slash, Uri is not valid. I do not think this is true. I looked at RFC 3986, and section 3.2.2 says:
If the URI contains an authority component, then the path component must either be empty or begin with a slash ("/").
He does not say that the final slash should be there.
source share