开发者

Combine complete URL and virtual URL, like a browser does

开发者 https://www.devze.com 2023-03-04 21:24 出处:网络
I ha开发者_如何学Pythonve a complete URL like: A: http://www.domain.com/aaa/bbb/ccc/ddd/eee.ext.

I ha开发者_如何学Pythonve a complete URL like: A: http://www.domain.com/aaa/bbb/ccc/ddd/eee.ext.

I have a relative URL like: B: ../../fff.ext

I’m 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 like what browsers does: you’re browsing URL A, then, page’s HTML have an hyperlink as B, the resulting URL is C.


You'd probably have better luck looking up "PathCanonicalize".

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

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

Proof is in the pudding

0

精彩评论

暂无评论...
验证码 换一张
取 消