Skip to content

Instantly share code, notes, and snippets.

@nicbell
Created September 26, 2016 11:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicbell/f235f0d38b58d218ca583432a2493e24 to your computer and use it in GitHub Desktop.
Save nicbell/f235f0d38b58d218ca583432a2493e24 to your computer and use it in GitHub Desktop.
Umbraco multiple hostnames, get correct url for a page, based on the domain of the current page.
public static class PublishedContentWrappedExtensions
{
public static string GetContextAwareUrl(this PublishedContentWrapped content)
{
var urls = new List<string>();
urls.Add(UmbracoContext.Current.RoutingContext.UrlProvider.GetUrl(content.Id));
urls.AddRange(UmbracoContext.Current.RoutingContext.UrlProvider.GetOtherUrls(content.Id));
var url = urls.FirstOrDefault(x => x.Contains(UmbracoContext.Current.HttpContext.Request.Url.Host));
if (url != null)
return url;
return content.Url;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment