Path.Combine for URLs?

前端 未结 30 2431
不思量自难忘°
不思量自难忘° 2020-11-22 14:28

Path.Combine is handy, but is there a similar function in the .NET framework for URLs?

I\'m looking for syntax like this:

Url.Combine(\"http://MyUrl.         


        
30条回答
  •  耶瑟儿~
    2020-11-22 15:27

    Uri has a constructor that should do this for you: new Uri(Uri baseUri, string relativeUri)

    Here's an example:

    Uri baseUri = new Uri("http://www.contoso.com");
    Uri myUri = new Uri(baseUri, "catalog/shownew.htm");
    

    Note from editor: Beware, this method does not work as expected. It can cut part of baseUri in some cases. See comments and other answers.

提交回复
热议问题