我一直在玩 Uri 构造函数的重载new Uri(baseUri, relativePath)
。也许其他人可能会发现结果很有用。这是我编写的测试应用程序的输出:
A) Base Address is domain only
==============================
NO trailing slash on base address, NO leading slash on relative path:
http://foo.com + relative1/relative2 :
http://foo.com/relative1/relative2
NO trailing slash on base address, relative path HAS leading slash:
http://foo.com + /relative1/relative2 :
http://foo.com/relative1/relative2
Base address HAS trailing slash, NO leading slash on relative path:
http://foo.com/ + relative1/relative2 :
http://foo.com/relative1/relative2
Base address HAS trailing slash, relative path HAS leading slash:
http://foo.com/ + /relative1/relative2 :
http://foo.com/relative1/relative2
B) Base Address includes path
=============================
NO trailing slash on base address, NO leading slash on relative path:
http://foo.com/base1/base2 + relative1/relative2 :
http://foo.com/base1/relative1/relative2
(removed base2 segment)
NO trailing slash on base address, relative path HAS leading slash:
http://foo.com/base1/base2 + /relative1/relative2 :
http://foo.com/relative1/relative2
(removed base1 and base2 segments)
Base address HAS trailing slash, NO leading slash on relative path:
http://foo.com/base1/base2/ + relative1/relative2 :
http://foo.com/base1/base2/relative1/relative2
(has all segments)
Base address HAS trailing slash, relative path HAS leading slash:
http://foo.com/base1/base2/ + /relative1/relative2 :
http://foo.com/relative1/relative2
(removed base1 and base2 segments)