title: How can I combine two urls the same way a browser does?
body: <p>I'm writing some kind of a page scraper, and one of the things I'm looking to do is combine the current url with an url fragment extracted from the current page. </p>
  
  <p>Like this:</p>
  
  <pre><code>if (WebPath.IsAbsolute(urlFragment))
      links.Add(new Uri(urlFragment));
  else
      links.Add(new Uri(currentUrl, urlFragment));
  </code></pre>
  
  <p>Easy peasy - this approach works most of the time, for both relative and absolute Uris.</p>
  
  <p><em>However</em>, some pages look like <a href="http://example.com/couple/of/folders/" rel="nofollow noreferrer">http://example.com/couple/of/folders/</a>, with the url fragment <a href="http://example.com/couple/of/otherfolders/" rel="nofollow noreferrer">couple/of/otherfolders/</a>. And every single browser out there interprets that as <a href="http://example.com/couple/of/otherfolders" rel="nofollow noreferrer">http://example.com/couple/of/otherfolders</a>.</p>
  
  <p>Of course, my code yields <a href="http://example.com/couple/of/folders/couple/of/otherfolders" rel="nofollow noreferrer">http://example.com/couple/of/folders/couple/of/otherfolders</a>. Which totally looks correct from the Uri's point of view - but I don't get how a browser can interpret this otherwise.</p>
  
  <p>Now, I've searched for a solution to this problem, but I only found people who didn't know how to combine two urls, so that didn't get me very far. Closest thing I found was this question: <a href="https://stackoverflow.com/questions/8244181/how-do-you-combine-url-fragments-in-java-the-same-way-browsers-do">How do you combine URL fragments in Java the same way browsers do?</a> , but the answer doesn't tackle my particular problem.</p>
  
  <p>Does anybody know what I'm missing?</p>
  
  <hr>
  
  <p>Edit - this is the IsAbsolute method (I know I should replace it with new Uri(link).IsAbsoluteUri):</p>
  
  <pre><code>public static bool IsAbsolute(string path)
  {
      var uppercasePath = path.ToUpper();
      return uppercasePath.StartsWith("HTTP://") || uppercasePath.StartsWith("HTTPS://");
  }
  </code></pre>