Created
September 26, 2016 11:18
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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