-
-
Save stefankip/e00d50a5c4711a29269c88049fc1976b to your computer and use it in GitHub Desktop.
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 class AliasUrlProvider : DefaultUrlProvider | |
{ | |
public AliasUrlProvider(IRequestHandlerSection requestSettings, ILogger logger, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper) | |
: base(requestSettings, logger, globalSettings, siteDomainHelper) | |
{ | |
} | |
public override UrlInfo GetUrl(UmbracoContext umbracoContext, IPublishedContent content, UrlMode mode, string culture, Uri current) | |
{ | |
var defaultUrlInfo = base.GetUrl(umbracoContext, content, mode, culture, current); | |
if (content == null || defaultUrlInfo == null) | |
{ | |
return defaultUrlInfo; | |
} | |
var uri = new Uri(defaultUrlInfo.Text, UriKind.RelativeOrAbsolute); | |
string url = null; | |
if (!string.IsNullOrEmpty(content.GetPropertyValue(Constants.Conventions.Content.UrlAlias))) | |
{ | |
url = $"{(uri.IsAbsoluteUri ? uri.GetLeftPart(UriPartial.Authority) : string.Empty)}/{content.GetPropertyValue(Constants.Conventions.Content.UrlAlias)}{(Current.Configs.Settings().RequestHandler.AddTrailingSlash ? "/" : string.Empty)}"; | |
} | |
return !string.IsNullOrEmpty(url) ? new UrlInfo(url, true, defaultUrlInfo.Culture) : defaultUrlInfo; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment