Using System.Uri to remove redundant slash

后端 未结 1 742
日久生厌
日久生厌 2020-12-19 00:24

I have a condition in my program where I have to combine a server (e.g. http://server1.my.corp/) that may or may not have an ending slash with a relative path (

1条回答
  •  天涯浪人
    2020-12-19 00:59

    Take a look at the constructors for the Uri class. You need to specify a base Uri and a relative path to get the canonized behavior. Try something like this:

    var server = new Uri("http://server1.my.corp/");
    var resource = new Uri(server, "/Apps/TestOne/");
    

    0 讨论(0)
提交回复
热议问题