Combine the full URL and a virtual URL, such as a browser

I have a full URL-address: .A: http://www.domain.com/aaa/bbb/ccc/ddd/eee.ext

I have a relative url: B: ../../fff.ext

I am looking for the easiest way in .NET C # to combine these two URLs and get: C: http://www.domain.com/aaa/bbb/fff.ext

This is similar to what browsers do: you look at URL A, and then the HTML pages have a hyperlink like B, the resulting URL is C.

+3
source share
1 answer

You will probably be able to find "PathCanonicalize".

Also, with my findings, one of Uri 's overloaded constructors can handle this:

Uri combined = new Uri(
  new Uri("http://www.domain.com/aaa/bbb/ccc/ddd/eee.ext", UriKind.Absolute),
  "../../fff.ext"
);

The proof is in the pudding

+5
source

All Articles