title: EpiServer - get absolute friendly url for given culture for page
body: <p>I've a following setup in my <strong>Manage Websites</strong> panel</p>
  <blockquote>
  <p>General Url is set to <em><strong>alloy.com</strong></em></p>
  <p><em><strong>alloy.no</strong></em> is set for <strong>no</strong> culture</p>
  <p><em><strong>alloy.se</strong></em> is set for <strong>sv</strong> culture</p>
  <p><em><strong>alloy.com</strong></em> is set for <strong>en</strong> culture</p>
  </blockquote>
  <p>In my code, i want to get the friendly external url for given language for given page.
  So for <strong>Search</strong> page I want to get absolute friendly url in all languages.</p>
  <p>I use following code to get friendly url for page (found on <a href="https://andersnordby.wordpress.com/2014/04/29/getting-an-external-url-in-episerver-7-x/" rel="nofollow noreferrer">Anders G. Nordby blog</a>):</p>
  
  <pre class="lang-cs prettyprint-override"><code>var urlResolver = ServiceLocator.Current.GetInstance&lt;UrlResolver&gt;();
  var pageAddress = urlResolver.GetUrl(reference, language);
  
  var builder = new UrlBuilder(pageAddress);
  
  Global.UrlRewriteProvider.ConvertToExternal(builder, null, Encoding.UTF8);
  
  var friendlyUrl = builder.Uri.IsAbsoluteUri
      ? builder.ToString()
      : UriSupport.AbsoluteUrlBySettings(builder.ToString());
  
  return friendlyUrl;
  </code></pre>
  <p>It is simple if I will use the <em><strong>alloy.com</strong></em> webpage and in my custom code generate friendly url.</p>
  <ul>
  <li><strong>no</strong> - <em><strong>alloy.no/søk</strong></em></li>
  <li><strong>se</strong> - <em><strong>alloy.se/sök</strong></em></li>
  <li><strong>en</strong> - <em><strong>alloy.com/search</strong></em></li>
  </ul>
  <p>But when I use <em><strong>alloy.no</strong></em> to enter edit mode and I will try to generate address for <strong>no</strong> i get <em>alloy.<strong>com</strong>/søk</em> when it should be <em>alloy.<strong>no</strong>/søk</em>.</p>
  <p>I found that if I use <em><strong>alloy.no</strong></em> to go to Edit Mode, code :</p>
  <pre class="lang-cs prettyprint-override"><code>urlResolver.GetUrl(reference, language)
  </code></pre>
  <p>returns only <em><strong>/søk</strong></em> and code</p>
  <pre class="lang-cs prettyprint-override"><code>UriSupport.AbsoluteUrlBySettings(builder.ToString())
  </code></pre>
  <p>add the General URL (alloy.com) instead of alloy.no.</p>
  <p>How can I improve this code to take correct host name for page in different culture?</p>