Absolute URL from base + relative URL in C#

后端 未结 2 643
生来不讨喜
生来不讨喜 2020-12-15 04:13

I have a base URL :

http://my.server.com/folder/directory/sample

And a relative one :

../../other/path

Ho

相关标签:
2条回答
  • 2020-12-15 04:51

    Some might be looking for Javascript solution that would allow conversion of urls 'on the fly' when debugging

    var absoluteUrl = function(href) {
        var link = document.createElement("a");
        link.href = href;
        return link.href;
    } 
    

    use like:

    absoluteUrl("http://google.com")

    http://google.com/

    or

    absoluteUrl("../../absolute")

    http://stackoverflow.com/absolute

    0 讨论(0)
  • 2020-12-15 04:53
    var baseUri = new Uri("http://my.server.com/folder/directory/sample");
    var absoluteUri = new Uri(baseUri,"../../other/path");
    

    OR

    Uri uri;
    if ( Uri.TryCreate("http://base/","../relative", out uri) ) doSomething(uri);
    
    0 讨论(0)
提交回复
热议问题