From 7ca6781d09b8cc398db3d4a08f1f9d6f1ec02e29 Mon Sep 17 00:00:00 2001 From: Marc Goodson Date: Tue, 10 Mar 2020 20:49:59 +0000 Subject: [PATCH] v7: Fix false matches for AltTemplate convention Urls (#7150) --- .../ContentFinderByNiceUrlAndTemplate.cs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web/Routing/ContentFinderByNiceUrlAndTemplate.cs b/src/Umbraco.Web/Routing/ContentFinderByNiceUrlAndTemplate.cs index f19886c4f2..f97e81791e 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByNiceUrlAndTemplate.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByNiceUrlAndTemplate.cs @@ -17,7 +17,7 @@ namespace Umbraco.Web.Routing /// /// Tries to find and assign an Umbraco document to a PublishedContentRequest. /// - /// The PublishedContentRequest. + /// The PublishedContentRequest. /// A value indicating whether an Umbraco document was found and assigned. /// If successful, also assigns the template. public override bool TryFindContent(PublishedContentRequest docRequest) @@ -43,16 +43,24 @@ namespace Umbraco.Web.Routing var route = docRequest.HasDomain ? (docRequest.Domain.RootNodeId.ToString() + path) : path; node = FindContent(docRequest, route); - - if (node.IsAllowedTemplate(template.Id)) + //not guaranteed to find a node - just because last portion of url contains a template alias, doesn't mean remaining part of the url is a published node + if (node != null) { - docRequest.TemplateModel = template; + if (node.IsAllowedTemplate(template.Id)) + { + docRequest.TemplateModel = template; + } + else + { + LogHelper.Warn("Configuration settings prevent template \"{0}\" from showing for node \"{1}\"", () => templateAlias, () => node.Id); + docRequest.PublishedContent = null; + node = null; + } } else { - LogHelper.Warn("Configuration settings prevent template \"{0}\" from showing for node \"{1}\"", () => templateAlias, () => node.Id); + LogHelper.Debug("Attempt to find content by alternative template alias: \"{0}\" triggered because end portion of url matched template alias, but no node exists for the url without the alt template alias at the route: \"{1}\"", () => templateAlias, () => route); docRequest.PublishedContent = null; - node = null; } } else @@ -68,4 +76,4 @@ namespace Umbraco.Web.Routing return node != null; } } -} \ No newline at end of file +}