From 1bffb7395cc3b1b0d908d88d7afec6f8e265bb71 Mon Sep 17 00:00:00 2001 From: Stephan Date: Tue, 20 Nov 2012 09:12:45 -0100 Subject: [PATCH] U4-1192 - uQuery.GetNodeIdByUrl should not follow redirects etc --- .../Routing/PublishedContentRequestBuilder.cs | 47 ++++++++++++------- .../umbraco/uQuery/uQuery-Nodes.cs | 6 ++- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/Umbraco.Web/Routing/PublishedContentRequestBuilder.cs b/src/Umbraco.Web/Routing/PublishedContentRequestBuilder.cs index 3bc9bf1bb0..41c82010b1 100644 --- a/src/Umbraco.Web/Routing/PublishedContentRequestBuilder.cs +++ b/src/Umbraco.Web/Routing/PublishedContentRequestBuilder.cs @@ -147,20 +147,11 @@ namespace Umbraco.Web.Routing const string tracePrefix = "LookupDocument: "; LogHelper.Debug("{0}Path=\"{1}\"", () => tracePrefix, () => _publishedContentRequest.Uri.AbsolutePath); - // look for the document - // the first successful resolver, if any, will set this.Node, and may also set this.Template - // some lookups may implement caching + // run the document lookups + LookupDocument1(); - using (DisposableTimer.DebugDuration( - () => string.Format("{0}Begin resolvers", tracePrefix), - () => string.Format("{0}End resolvers, {1}", tracePrefix, (_publishedContentRequest.HasNode ? "a document was found" : "no document was found")))) - { - _routingContext.DocumentLookups.Any(lookup => lookup.TrySetDocument(_publishedContentRequest)); - } - - // fixme - not handling umbracoRedirect - // should come after internal redirects - // so after ResolveDocument2() => docreq.IsRedirect => handled by the module! + // not handling umbracoRedirect here but after LookupDocument2 + // so internal redirect, 404, etc has precedence over redirect // handle not-found, redirects, access, template LookupDocument2(); @@ -175,6 +166,26 @@ namespace Umbraco.Web.Routing return resolved; } + /// + /// Performs the document resolution first pass. + /// + /// The first past consists in running the document lookups. + internal void LookupDocument1() + { + const string tracePrefix = "LookupDocument: "; + + // look for the document + // the first successful resolver, if any, will set this.Node, and may also set this.Template + // some lookups may implement caching + + using (DisposableTimer.DebugDuration( + () => string.Format("{0}Begin resolvers", tracePrefix), + () => string.Format("{0}End resolvers, {1}", tracePrefix, (_publishedContentRequest.HasNode ? "a document was found" : "no document was found")))) + { + _routingContext.DocumentLookups.Any(lookup => lookup.TrySetDocument(_publishedContentRequest)); + } + } + /// /// Performs the document resolution second pass. /// @@ -221,10 +232,6 @@ namespace Umbraco.Web.Routing if (_publishedContentRequest.HasNode) EnsureNodeAccess(); - // resolve template - if (_publishedContentRequest.HasNode) - LookupTemplate(); - // loop while we don't have page, ie the redirect or access // got us to nowhere and now we need to run the notFoundLookup again // as long as it's not running out of control ie infinite loop of some sort @@ -237,6 +244,12 @@ namespace Umbraco.Web.Routing _publishedContentRequest.PublishedContent = null; } + // resolve template - will do nothing if a template is already set + // moved out of the loop because LookupTemplate does set .PublishedContent to null anymore + // (see node in LookupTemplate) + if (_publishedContentRequest.HasNode) + LookupTemplate(); + LogHelper.Debug("{0}End", () => tracePrefix); } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/uQuery-Nodes.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/uQuery-Nodes.cs index 371357fc47..b28bcadd89 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/uQuery-Nodes.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/uQuery-Nodes.cs @@ -198,7 +198,9 @@ namespace umbraco /// The URL to get the XML node from. /// Returns the node Id. /// - /// Thanks to Jonas Eriksson http://our.umbraco.org/member/4853 + /// Thanks to Jonas Eriksson http://our.umbraco.org/member/4853 + /// Just runs lookups to find the document, does not follow internal redirects, 404 handlers, + /// page access verification, wildcard domains -- nothing. /// public static int GetNodeIdByUrl(string url) { @@ -210,7 +212,7 @@ namespace umbraco var docreq = new Umbraco.Web.Routing.PublishedContentRequest(uri, Umbraco.Web.UmbracoContext.Current.RoutingContext); var builder = new Umbraco.Web.Routing.PublishedContentRequestBuilder(docreq); builder.LookupDomain(); - builder.LookupDocument(); + builder.LookupDocument1(); // will _not_ follow redirects, handle 404, nothing - just run lookups return docreq.HasNode ? docreq.DocumentId : uQuery.RootNodeId; }