I need to combine two URLs that contain .Path information.
I would like to use Uri.TryCreate () to enable me, so I can catch the wrong URLs.
The problem I am facing is that the base URI of the path is ignored when I combine the absolute and relative URIs:
Uri absoluteUri= new Uri("http://hostname/path/", UriKind.Absolute);
Uri relativeUri = new Uri("/my subsite/my page.aspx?my=query", UriKind.Relative);
Uri resultUri;
if (!Uri.TryCreate(absoluteUri, relativeUri, out resultUri))
The conclusion above:
http://hostname/my%20subsite/my%20page.aspx?my=query
I would like to:
http://hostname/path/my%20subsite/my%20page.aspx?my=query
Is there a way to combine URLs that contain path information using a class Uri?
source
share