diff --git a/src/Orchard/UI/Navigation/NavigationHelper.cs b/src/Orchard/UI/Navigation/NavigationHelper.cs index 880742e53..7b028d9ce 100644 --- a/src/Orchard/UI/Navigation/NavigationHelper.cs +++ b/src/Orchard/UI/Navigation/NavigationHelper.cs @@ -80,11 +80,24 @@ namespace Orchard.UI.Navigation { /// The current route data. /// A stack with the selection path being the last node the currently selected one. public static Stack SetSelectedPath(IEnumerable menuItems, HttpRequestBase currentRequest, RouteValueDictionary currentRouteData) { - if (menuItems == null) - return null; + // doing route data comparison first and if that fails, fallback to string-based URL lookup + var path = SetSelectedPath(menuItems, currentRequest, currentRouteData, false) + ?? SetSelectedPath(menuItems, currentRequest, currentRouteData, true); + return path; + } + + /// + /// Identifies the currently selected path, starting from the selected node. + /// + /// All the menuitems in the navigation menu. + /// The currently executed request if any + /// The current route data. + /// Should compare raw string URLs instead of route data. + /// A stack with the selection path being the last node the currently selected one. + private static Stack SetSelectedPath(IEnumerable menuItems, HttpRequestBase currentRequest, RouteValueDictionary currentRouteData, bool compareUrls) { foreach (MenuItem menuItem in menuItems) { - Stack selectedPath = SetSelectedPath(menuItem.Items, currentRequest, currentRouteData); + Stack selectedPath = SetSelectedPath(menuItem.Items, currentRequest, currentRouteData, compareUrls); if (selectedPath != null) { menuItem.Selected = true; selectedPath.Push(menuItem); @@ -92,10 +105,11 @@ namespace Orchard.UI.Navigation { } // compare route values (if any) first - bool match = menuItem.RouteValues != null && RouteMatches(menuItem.RouteValues, currentRouteData); + // if URL string comparison is used it means all previous route matches failed, thus no need to do them twice + bool match = !compareUrls && menuItem.RouteValues != null && RouteMatches(menuItem.RouteValues, currentRouteData); - // if route match failed, try comparing URL strings - if (currentRequest != null && !match) { + // if route match failed, try comparing URL strings, if + if (currentRequest != null && !match && compareUrls) { string appPath = currentRequest.ApplicationPath ?? "/"; string requestUrl = currentRequest.Path.StartsWith(appPath) ? currentRequest.Path.Substring(appPath.Length) : currentRequest.Path;