From b27c03f001a4eb44f9a520b0bc38effee0261b22 Mon Sep 17 00:00:00 2001 From: vsilvar Date: Mon, 18 Jul 2022 00:47:45 +0200 Subject: [PATCH] Fixed ContentLastChanceFinder not being called for nodes without template (#12002) This commit also ensure that the domain and culture is set before the ContentLastChanceFinder executes --- src/Umbraco.Core/Routing/PublishedRouter.cs | 18 ++++++----- .../Routing/UmbracoRouteValuesFactory.cs | 31 ++++++++++++------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/Umbraco.Core/Routing/PublishedRouter.cs b/src/Umbraco.Core/Routing/PublishedRouter.cs index 5f195f78b5..63df65c6e0 100644 --- a/src/Umbraco.Core/Routing/PublishedRouter.cs +++ b/src/Umbraco.Core/Routing/PublishedRouter.cs @@ -127,11 +127,18 @@ public class PublishedRouter : IPublishedRouter IPublishedRequestBuilder builder = new PublishedRequestBuilder(request.Uri, _fileService); + // ensure we keep the previous domain and culture + if (request.Domain is not null) + { + builder.SetDomain(request.Domain); + } + builder.SetCulture(request.Culture); + // set to the new content (or null if specified) builder.SetPublishedContent(publishedContent); // re-route - await RouteRequestInternalAsync(builder); + await RouteRequestInternalAsync(builder, true); // return if we are redirect if (builder.IsRedirect()) @@ -147,11 +154,6 @@ public class PublishedRouter : IPublishedRouter builder.SetPublishedContent(content); } - if (!builder.HasDomain()) - { - FindDomain(builder); - } - return BuildRequest(builder); } @@ -211,7 +213,7 @@ public class PublishedRouter : IPublishedRouter _variationContextAccessor.VariationContext = new VariationContext(culture); } - private async Task RouteRequestInternalAsync(IPublishedRequestBuilder builder) + private async Task RouteRequestInternalAsync(IPublishedRequestBuilder builder, bool skipContentFinders = false) { // if request builder was already flagged to redirect then return // whoever called us is in charge of actually redirecting @@ -229,7 +231,7 @@ public class PublishedRouter : IPublishedRouter // This could be manually assigned with a custom route handler, etc... // which in turn could call this method // to setup the rest of the pipeline but we don't want to run the finders since there's one assigned. - if (!builder.HasPublishedContent()) + if (!builder.HasPublishedContent() && !skipContentFinders) { if (_logger.IsEnabled(LogLevel.Debug)) { diff --git a/src/Umbraco.Web.Website/Routing/UmbracoRouteValuesFactory.cs b/src/Umbraco.Web.Website/Routing/UmbracoRouteValuesFactory.cs index 8eb181003f..d8fbca45d4 100644 --- a/src/Umbraco.Web.Website/Routing/UmbracoRouteValuesFactory.cs +++ b/src/Umbraco.Web.Website/Routing/UmbracoRouteValuesFactory.cs @@ -75,17 +75,7 @@ public class UmbracoRouteValuesFactory : IUmbracoRouteValuesFactory throw new ArgumentNullException(nameof(request)); } - string? customActionName = null; - - // check that a template is defined), if it doesn't and there is a hijacked route it will just route - // to the index Action - if (request.HasTemplate()) - { - // the template Alias should always be already saved with a safe name. - // if there are hyphens in the name and there is a hijacked route, then the Action will need to be attributed - // with the action name attribute. - customActionName = request.GetTemplateAlias()?.Split('.')[0].ToSafeAlias(_shortStringHelper); - } + string? customActionName = GetTemplateName(request); // The default values for the default controller/action var def = new UmbracoRouteValues( @@ -160,10 +150,12 @@ public class UmbracoRouteValuesFactory : IUmbracoRouteValuesFactory $"The call to {nameof(IPublishedRouter.UpdateRequestAsync)} cannot return null"); } + string? customActionName = GetTemplateName(request); + def = new UmbracoRouteValues( request, def.ControllerActionDescriptor, - def.TemplateName); + customActionName); // if the content has changed, we must then again check for hijacked routes if (content != request.PublishedContent) @@ -174,4 +166,19 @@ public class UmbracoRouteValuesFactory : IUmbracoRouteValuesFactory return def; } + + private string? GetTemplateName(IPublishedRequest request) + { + // check that a template is defined), if it doesn't and there is a hijacked route it will just route + // to the index Action + if (request.HasTemplate()) + { + // the template Alias should always be already saved with a safe name. + // if there are hyphens in the name and there is a hijacked route, then the Action will need to be attributed + // with the action name attribute. + return request.GetTemplateAlias()?.Split('.')[0].ToSafeAlias(_shortStringHelper); + } + + return null; + } }