From b9c2d5122976b5dcfaf0263a5da643a7cd6d7e82 Mon Sep 17 00:00:00 2001 From: Venkatesan R <venkateeian@gmail.com> Date: Sat, 26 Nov 2022 23:34:03 +0530 Subject: [PATCH] Added /Admin relative URL for admin menu nodes (#12807) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jean-Thierry Kéchichian <jean-thierry.kechichian@wanadoo.fr> --- .../NavigationManager.cs | 14 ++++++++++++-- .../OrchardCore.Navigation.Core.csproj | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore/OrchardCore.Navigation.Core/NavigationManager.cs b/src/OrchardCore/OrchardCore.Navigation.Core/NavigationManager.cs index 32f2ef7a6bc..9b144f2d6cf 100644 --- a/src/OrchardCore/OrchardCore.Navigation.Core/NavigationManager.cs +++ b/src/OrchardCore/OrchardCore.Navigation.Core/NavigationManager.cs @@ -8,6 +8,8 @@ using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using OrchardCore.Admin; using OrchardCore.Environment.Shell; namespace OrchardCore.Navigation @@ -19,6 +21,7 @@ public class NavigationManager : INavigationManager protected readonly ShellSettings _shellSettings; private readonly IUrlHelperFactory _urlHelperFactory; private readonly IAuthorizationService _authorizationService; + private readonly AdminOptions _adminOptions; private IUrlHelper _urlHelper; @@ -27,7 +30,8 @@ public NavigationManager( ILogger<NavigationManager> logger, ShellSettings shellSettings, IUrlHelperFactory urlHelperFactory, - IAuthorizationService authorizationService + IAuthorizationService authorizationService, + IOptions<AdminOptions> adminOptions ) { _navigationProviders = navigationProviders; @@ -35,6 +39,7 @@ IAuthorizationService authorizationService _shellSettings = shellSettings; _urlHelperFactory = urlHelperFactory; _authorizationService = authorizationService; + _adminOptions = adminOptions.Value; } public async Task<IEnumerable<MenuItem>> BuildMenuAsync(string name, ActionContext actionContext) @@ -203,8 +208,13 @@ private string GetUrl(string menuItemUrl, RouteValueDictionary routeValueDiction menuItemUrl = menuItemUrl.Substring(2); } + if (menuItemUrl.StartsWith($"{_adminOptions.AdminUrlPrefix}/", StringComparison.OrdinalIgnoreCase)) + { + return actionContext.HttpContext.Request.PathBase.Add($"/{menuItemUrl}").Value; + } + // Use the unescaped 'Value' to not encode some possible reserved delimiters. - return actionContext.HttpContext.Request.PathBase.Add('/' + menuItemUrl).Value; + return actionContext.HttpContext.Request.PathBase.Add($"/{_adminOptions.AdminUrlPrefix}/{menuItemUrl}").Value; } /// <summary> diff --git a/src/OrchardCore/OrchardCore.Navigation.Core/OrchardCore.Navigation.Core.csproj b/src/OrchardCore/OrchardCore.Navigation.Core/OrchardCore.Navigation.Core.csproj index 44de0240a06..8e08bd71cd1 100644 --- a/src/OrchardCore/OrchardCore.Navigation.Core/OrchardCore.Navigation.Core.csproj +++ b/src/OrchardCore/OrchardCore.Navigation.Core/OrchardCore.Navigation.Core.csproj @@ -14,6 +14,7 @@ </ItemGroup> <ItemGroup> + <ProjectReference Include="..\OrchardCore.Admin.Abstractions\OrchardCore.Admin.Abstractions.csproj" /> <ProjectReference Include="..\OrchardCore.Infrastructure.Abstractions\OrchardCore.Infrastructure.Abstractions.csproj" /> </ItemGroup>