Base Uri without a trailing slash

前端 未结 2 1877
走了就别回头了
走了就别回头了 2021-01-17 19:19

If I create a Uri using the UriBuilder like this:

var rootUrl = new UriBuilder(\"http\", \"example.com\", 50000).Uri;
2条回答
  •  天命终不由人
    2021-01-17 20:12

    You can use the Uri.GetComponents method:

    rootUrl.GetComponents(UriComponents.SchemeAndServer, UriFormat.UriEscaped)
    

    Which would return a string representation of the Uri's different components, in this case, UriComponents.SchemeAndServer means the scheme, host, and port components.

    You can read more about it on MSDN:

    1. Uri.GetComponents

    2. UriComponents

    3. UriFormat

提交回复
热议问题