diff --git a/src/Umbraco.Web/PublishedCache/NuCache/ContentCache.cs b/src/Umbraco.Web/PublishedCache/NuCache/ContentCache.cs index c7661a3f28..0341d2dcf5 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/ContentCache.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/ContentCache.cs @@ -148,6 +148,11 @@ namespace Umbraco.Web.PublishedCache.NuCache while (hasDomains == false && n != null) // n is null at root { var urlName = n.GetUrlName(_localizationService, culture); + if (urlName == null) + { + //we cannot continue, it will be null if the item is not published + return null; + } pathParts.Add(urlName); diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs index e4a3a85d13..a33b8f283a 100644 --- a/src/Umbraco.Web/PublishedContentExtensions.cs +++ b/src/Umbraco.Web/PublishedContentExtensions.cs @@ -1243,11 +1243,15 @@ namespace Umbraco.Web if (cultureCode != null && content.CultureNames.TryGetValue(cultureCode, out var cultureName)) { return cultureName.UrlName; - } + } + //there is no name for the specified culture (unpublished perhaps) + return null; + } + else + { + //the content type is invariant + return content.UrlName; } - - //if we get here, the content type is invariant or we don't have access to a usable culture code - return content.UrlName; } #endregion diff --git a/src/Umbraco.Web/Routing/PublishedRouter.cs b/src/Umbraco.Web/Routing/PublishedRouter.cs index f85d2d6c28..add9c4ad3b 100644 --- a/src/Umbraco.Web/Routing/PublishedRouter.cs +++ b/src/Umbraco.Web/Routing/PublishedRouter.cs @@ -266,10 +266,27 @@ namespace Umbraco.Web.Routing _logger.Debug(() => $"{tracePrefix}Uri=\"{request.Uri}\""); var domainsCache = request.UmbracoContext.PublishedSnapshot.Domains; + var domains = domainsCache.GetAll(includeWildcards: false).ToList(); + var contentForDomains = new Dictionary(); + //filter the domains to ensure that any referenced content is actually published + domains = domains.Where(x => + { + //get or look up the content assigned + if (!contentForDomains.TryGetValue(x.ContentId, out var contentForDomain)) + { + contentForDomain = request.UmbracoContext.PublishedSnapshot.Content.GetById(x.ContentId); + contentForDomains[x.ContentId] = contentForDomain; + } - //get the domains but filter to ensure that any referenced content is actually published - var domains = domainsCache.GetAll(includeWildcards: false) - .Where(x => request.UmbracoContext.PublishedSnapshot.Content.GetById(x.ContentId) != null); + //definitely not published + if (contentForDomain == null) + return false; + //invariant so no need to check variations + if (!contentForDomain.ContentType.Variations.Has(ContentVariation.CultureNeutral)) + return true; + //variant so ensure the culture name exists + return contentForDomain.CultureNames.ContainsKey(x.Culture.Name); + }).ToList(); var defaultCulture = domainsCache.DefaultCulture;