From e394879b8902802afc12cc5401c0caecd567b401 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Wed, 5 Feb 2014 16:02:17 -0800 Subject: [PATCH] Fixing local navigation with tenants --- .../Core/Navigation/Services/NavigationManager.cs | 13 ++++++++++--- src/Orchard/UI/Navigation/NavigationHelper.cs | 7 ++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Orchard.Web/Core/Navigation/Services/NavigationManager.cs b/src/Orchard.Web/Core/Navigation/Services/NavigationManager.cs index 02d92e677..dd476349d 100644 --- a/src/Orchard.Web/Core/Navigation/Services/NavigationManager.cs +++ b/src/Orchard.Web/Core/Navigation/Services/NavigationManager.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Web.Mvc; using System.Web.Routing; using Orchard.ContentManagement; +using Orchard.Environment.Configuration; using Orchard.Logging; using Orchard.Security; using Orchard.Security.Permissions; @@ -19,6 +20,7 @@ namespace Orchard.Core.Navigation.Services { private readonly IEnumerable _navigationFilters; private readonly UrlHelper _urlHelper; private readonly IOrchardServices _orchardServices; + private readonly ShellSettings _shellSettings; public NavigationManager( IEnumerable navigationProviders, @@ -26,13 +28,15 @@ namespace Orchard.Core.Navigation.Services { IAuthorizationService authorizationService, IEnumerable navigationFilters, UrlHelper urlHelper, - IOrchardServices orchardServices) { + IOrchardServices orchardServices, + ShellSettings shellSettings) { _navigationProviders = navigationProviders; _menuProviders = menuProviders; _authorizationService = authorizationService; _navigationFilters = navigationFilters; _urlHelper = urlHelper; _orchardServices = orchardServices; + _shellSettings = shellSettings; Logger = NullLogger.Instance; } @@ -60,7 +64,7 @@ namespace Orchard.Core.Navigation.Services { return GetImageSets(menuName).SelectMany(imageSets => imageSets.Distinct()).Distinct(); } - private IEnumerable FinishMenu(IEnumerable menuItems) { + private IEnumerable FinishMenu(ICollection menuItems) { foreach (var menuItem in menuItems) { menuItem.Href = GetUrl(menuItem.Url, menuItem.RouteValues); menuItem.Items = FinishMenu(menuItem.Items.ToArray()); @@ -89,7 +93,10 @@ namespace Orchard.Core.Navigation.Services { if (!string.IsNullOrEmpty(url) && _urlHelper.RequestContext.HttpContext != null && !(url.StartsWith("/") || schemes.Any(scheme => url.StartsWith(scheme + ":")))) { if (url.StartsWith("~/")) { - url = url.Substring(2); + + if (!String.IsNullOrEmpty(_shellSettings.RequestUrlPrefix)) { + url = _shellSettings.RequestUrlPrefix + "/" + url.Substring(2); + } } if (!url.StartsWith("#")) { var appPath = _urlHelper.RequestContext.HttpContext.Request.ApplicationPath; diff --git a/src/Orchard/UI/Navigation/NavigationHelper.cs b/src/Orchard/UI/Navigation/NavigationHelper.cs index 935a2909d..8ef6807c2 100644 --- a/src/Orchard/UI/Navigation/NavigationHelper.cs +++ b/src/Orchard/UI/Navigation/NavigationHelper.cs @@ -95,9 +95,10 @@ namespace Orchard.UI.Navigation { // if the menu item doesn't have route values, compare urls if (currentRequest != null && menuItem.RouteValues == null) { - string requestUrl = currentRequest.Path.Replace(currentRequest.ApplicationPath, string.Empty).TrimEnd('/').ToUpperInvariant(); - string modelUrl = menuItem.Href.Replace(currentRequest.ApplicationPath, string.Empty).TrimEnd('/').ToUpperInvariant(); - if (requestUrl == modelUrl || (!string.IsNullOrEmpty(modelUrl) && requestUrl.StartsWith(modelUrl + "/"))) { + string requestUrl = currentRequest.Path.Replace(currentRequest.ApplicationPath ?? "/", string.Empty); + string modelUrl = menuItem.Href.Replace("~/", currentRequest.ApplicationPath); + modelUrl = modelUrl.Replace(currentRequest.ApplicationPath ?? "/", string.Empty); + if (requestUrl.Equals(modelUrl, StringComparison.OrdinalIgnoreCase) || (!string.IsNullOrEmpty(modelUrl) && requestUrl.StartsWith(modelUrl + "/", StringComparison.OrdinalIgnoreCase))) { match = true; } }