diff --git a/src/Umbraco.Core/Routing/IPublishedRequest.cs b/src/Umbraco.Core/Routing/IPublishedRequest.cs index f05df351f3..4ffe565489 100644 --- a/src/Umbraco.Core/Routing/IPublishedRequest.cs +++ b/src/Umbraco.Core/Routing/IPublishedRequest.cs @@ -25,13 +25,6 @@ namespace Umbraco.Web.Routing /// IPublishedContent PublishedContent { get; } - /// - /// Gets the initial requested content. - /// - /// The initial requested content is the content that was found by the finders, - /// before anything such as 404, redirect... took place. - IPublishedContent InitialPublishedContent { get; } - /// /// Gets a value indicating whether the current published content has been obtained /// from the initial published content following internal redirections exclusively. diff --git a/src/Umbraco.Core/Routing/IPublishedRequestBuilder.cs b/src/Umbraco.Core/Routing/IPublishedRequestBuilder.cs index fee64fda8d..f94972412f 100644 --- a/src/Umbraco.Core/Routing/IPublishedRequestBuilder.cs +++ b/src/Umbraco.Core/Routing/IPublishedRequestBuilder.cs @@ -28,11 +28,6 @@ namespace Umbraco.Web.Routing /// CultureInfo Culture { get; } - /// - /// Gets a value indicating whether the current published content is the initial one. - /// - bool IsInitialPublishedContent { get; } - /// /// Gets a value indicating whether the current published content has been obtained /// from the initial published content following internal redirections exclusively. @@ -84,11 +79,6 @@ namespace Umbraco.Web.Routing /// preserve or reset the template, if any. IPublishedRequestBuilder SetInternalRedirectPublishedContent(IPublishedContent content); - /// - /// Indicates that the current PublishedContent is the initial one. - /// - IPublishedRequestBuilder SetIsInitialPublishedContent(); // TODO: Required? - /// /// Tries to set the template to use to display the requested content. /// diff --git a/src/Umbraco.Core/Routing/PublishedRequest.cs b/src/Umbraco.Core/Routing/PublishedRequest.cs index b3aa37d31e..135a756600 100644 --- a/src/Umbraco.Core/Routing/PublishedRequest.cs +++ b/src/Umbraco.Core/Routing/PublishedRequest.cs @@ -76,10 +76,7 @@ namespace Umbraco.Web.Routing public bool CacheabilityNoCache { get; } } - /// - /// Represents a request for one specified Umbraco IPublishedContent to be rendered - /// by one specified template, using one specified Culture and RenderingEngine. - /// + // TODO: Kill this, but we need to port all of it's functionality public class PublishedRequestOld // : IPublishedRequest { private readonly IPublishedRouter _publishedRouter; diff --git a/src/Umbraco.Core/Routing/PublishedRequestBuilder.cs b/src/Umbraco.Core/Routing/PublishedRequestBuilder.cs index 8167e83e6a..6441fcabf7 100644 --- a/src/Umbraco.Core/Routing/PublishedRequestBuilder.cs +++ b/src/Umbraco.Core/Routing/PublishedRequestBuilder.cs @@ -16,7 +16,6 @@ namespace Umbraco.Web.Routing private bool _cacheability; private IReadOnlyList _cacheExtensions; private IPublishedContent _internalRedirectContent; - private bool _isInitContent; private string _redirectUrl; private HttpStatusCode _responseStatus = HttpStatusCode.NotFound; private string _responseDesc; @@ -41,9 +40,6 @@ namespace Umbraco.Web.Routing /// public ITemplate Template { get; private set; } - /// - public bool IsInitialPublishedContent { get; private set; } - /// public bool IsInternalRedirectPublishedContent { get; private set; } // TODO: Not sure what this is yet @@ -124,13 +120,6 @@ namespace Umbraco.Web.Routing return this; } - /// - public IPublishedRequestBuilder SetIsInitialPublishedContent() - { - _isInitContent = true; - return this; - } - /// public IPublishedRequestBuilder SetPublishedContent(IPublishedContent content) { diff --git a/src/Umbraco.Core/Routing/PublishedRequestExtensions.cs b/src/Umbraco.Core/Routing/PublishedRequestExtensions.cs index f9c9d8b294..b3eb21ed16 100644 --- a/src/Umbraco.Core/Routing/PublishedRequestExtensions.cs +++ b/src/Umbraco.Core/Routing/PublishedRequestExtensions.cs @@ -55,11 +55,6 @@ namespace Umbraco.Web.Routing /// public static bool IsRedirectPermanent(this IPublishedRequest publishedRequest) => publishedRequest.ResponseStatusCode == (int)HttpStatusCode.Moved; - /// - /// Gets a value indicating whether the current published content is the initial one. - /// - public static bool IsInitialPublishedContent(this IPublishedRequest publishedRequest) => publishedRequest.InitialPublishedContent != null; - /// /// Gets a value indicating whether the content request has a domain. /// diff --git a/src/Umbraco.Core/Routing/PublishedRouter.cs b/src/Umbraco.Core/Routing/PublishedRouter.cs index a7b20b84ba..7f4bc6f22f 100644 --- a/src/Umbraco.Core/Routing/PublishedRouter.cs +++ b/src/Umbraco.Core/Routing/PublishedRouter.cs @@ -318,13 +318,15 @@ namespace Umbraco.Web.Routing internal bool FindTemplateRenderingEngineInDirectory(DirectoryInfo directory, string alias, string[] extensions) { if (directory == null || directory.Exists == false) + { return false; + } var pos = alias.IndexOf('/'); if (pos > 0) { // recurse - var subdir = directory.GetDirectories(alias.Substring(0, pos)).FirstOrDefault(); + DirectoryInfo subdir = directory.GetDirectories(alias.Substring(0, pos)).FirstOrDefault(); alias = alias.Substring(pos + 1); return subdir != null && FindTemplateRenderingEngineInDirectory(subdir, alias, extensions); } @@ -351,6 +353,8 @@ namespace Umbraco.Web.Routing return; } + var foundContentByFinders = request.HasPublishedContent(); + // not handling umbracoRedirect here but after LookupDocument2 // so internal redirect, 404, etc has precedence over redirect @@ -358,7 +362,7 @@ namespace Umbraco.Web.Routing HandlePublishedContent(request); // find a template - FindTemplate(request); + FindTemplate(request, foundContentByFinders); // handle umbracoRedirect FollowExternalRedirect(request); @@ -375,7 +379,6 @@ namespace Umbraco.Web.Routing // look for the document // the first successful finder, if any, will set this.PublishedContent, and may also set this.Template // some finders may implement caching - using (_profilingLogger.DebugDuration( $"{tracePrefix}Begin finders", $"{tracePrefix}End finders")) @@ -387,10 +390,6 @@ namespace Umbraco.Web.Routing return finder.TryFindContent(request); }); } - - // indicate that the published content (if any) we have at the moment is the - // one that was found by the standard finders before anything else took place. - request.SetIsInitialPublishedContent(); } /// @@ -588,7 +587,9 @@ namespace Umbraco.Web.Routing /// /// Finds a template for the current node, if any. /// - private void FindTemplate(IPublishedRequestBuilder request) + /// The request builder. + /// If the content was found by the finders, before anything such as 404, redirect... took place. + private void FindTemplate(IPublishedRequestBuilder request, bool contentFoundByFinders) { // TODO: We've removed the event, might need to re-add? // NOTE: at the moment there is only 1 way to find a template, and then ppl must @@ -604,7 +605,7 @@ namespace Umbraco.Web.Routing // only if the published content is the initial once, else the alternate template // does not apply // + optionally, apply the alternate template on internal redirects - var useAltTemplate = request.IsInitialPublishedContent + var useAltTemplate = contentFoundByFinders || (_webRoutingSettings.InternalRedirectPreservesTemplate && request.IsInternalRedirectPublishedContent); var altTemplate = useAltTemplate diff --git a/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs b/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs index 7b0fed7991..f087a6203e 100644 --- a/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs +++ b/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs @@ -218,15 +218,14 @@ namespace Umbraco.Web.Website.Routing // ok, process - // note: requestModule.UmbracoRewrite also did some stripping of &umbPage - // from the querystring... that was in v3.x to fix some issues with pre-forms - // auth. Paul Sterling confirmed in Jan. 2013 that we can get rid of it. - // instantiate, prepare and process the published content request // important to use CleanedUmbracoUrl - lowercase path-only version of the current url IPublishedRequestBuilder requestBuilder = _publishedRouter.CreateRequest(umbracoContext.CleanedUmbracoUrl); - // TODO: This is ugly with the re-assignment to umbraco context + // TODO: This is ugly with the re-assignment to umbraco context but at least its now + // an immutable object. The only way to make this better would be to have a RouteRequest + // as part of UmbracoContext but then it will require a PublishedRouter dependency so not sure that's worth it. + // Maybe could be a one-time Set method instead? publishedRequest = umbracoContext.PublishedRequest = _publishedRouter.RouteRequest(requestBuilder); return publishedRequest.Success() && publishedRequest.HasPublishedContent();