mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 16:11:10 +00:00
Renders every page through the themed shell with a themed navigation menu
This commit is contained in:
1 parent
e37bb3ecc6
commit
4ef8570854
19 files changed
+707
-104
No files matched your search
@@ -0,0 +1,64 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Renders a Razor partial to a string, so that the application chrome can be reused by the themed layout renderer.
|
||||
/// </summary>
|
||||
public sealed class RazorViewToStringRenderer
|
||||
{
|
||||
private readonly ICompositeViewEngine _viewEngine;
|
||||
private readonly ITempDataProvider _tempDataProvider;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RazorViewToStringRenderer"/> class.
|
||||
/// </summary>
|
||||
/// <param name="viewEngine">Injected engine used to resolve the partial to render.</param>
|
||||
/// <param name="tempDataProvider">Injected provider used to create the temp data dictionary of the view context.</param>
|
||||
/// <param name="serviceProvider">Injected service provider used to resolve the model metadata provider.</param>
|
||||
/// <param name="httpContextAccessor">Injected accessor for the current HTTP context.</param>
|
||||
public RazorViewToStringRenderer(ICompositeViewEngine viewEngine, ITempDataProvider tempDataProvider, IServiceProvider serviceProvider, IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_viewEngine = viewEngine;
|
||||
_tempDataProvider = tempDataProvider;
|
||||
_serviceProvider = serviceProvider;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the partial with the specified name to a string.
|
||||
/// </summary>
|
||||
/// <param name="partialName">The name of the partial to render.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The rendered HTML of the partial.</returns>
|
||||
public async Task<string> RenderPartialAsync(string partialName, CancellationToken cancellationToken = default)
|
||||
{
|
||||
HttpContext httpContext = _httpContextAccessor.HttpContext ?? throw new InvalidOperationException("The current HTTP context is unavailable.");
|
||||
ActionContext actionContext = new(httpContext, httpContext.GetRouteData() ?? new RouteData(), new ActionDescriptor());
|
||||
IView view = _viewEngine.FindView(actionContext, partialName, isMainPage: false).View
|
||||
?? throw new InvalidOperationException($"The partial '{partialName}' could not be found.");
|
||||
|
||||
IModelMetadataProvider metadataProvider = _serviceProvider.GetRequiredService<IModelMetadataProvider>();
|
||||
ViewDataDictionary viewData = new(metadataProvider, new ModelStateDictionary());
|
||||
using StringWriter writer = new();
|
||||
ViewContext viewContext = new(actionContext, view, viewData, new TempDataDictionary(httpContext, _tempDataProvider), writer, new HtmlHelperOptions());
|
||||
await view.RenderAsync(viewContext).ConfigureAwait(false);
|
||||
return writer.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Primitives;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Renders the themed shell of a page, wrapping the page section in the layout and navigation templates of the active theme.
|
||||
/// </summary>
|
||||
public class ThemeLayoutRenderer
|
||||
{
|
||||
// the page keys mirror the paths of the corresponding Razor views under Core/Views, so that theme templates can override them at the page, section or default scope
|
||||
private const string LAYOUT_PAGE_KEY = "shared/layout";
|
||||
private const string NAV_PAGE_KEY = "shared/nav-menu";
|
||||
|
||||
private readonly ThemeService _themeService;
|
||||
private readonly ThemeTemplateEngine _templateEngine;
|
||||
private readonly RazorViewToStringRenderer _viewRenderer;
|
||||
private readonly ThemeNavBuilder _navBuilder;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ThemeLayoutRenderer"/> class.
|
||||
/// </summary>
|
||||
/// <param name="themeService">The service that resolves the render documents.</param>
|
||||
/// <param name="templateEngine">The template engine used to render the documents.</param>
|
||||
/// <param name="viewRenderer">The renderer used to produce the application chrome fragments.</param>
|
||||
/// <param name="navBuilder">The builder used to produce the navigation menu model.</param>
|
||||
/// <param name="httpContextAccessor">Injected accessor for the current HTTP context.</param>
|
||||
public ThemeLayoutRenderer(ThemeService themeService, ThemeTemplateEngine templateEngine, RazorViewToStringRenderer viewRenderer, ThemeNavBuilder navBuilder, IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_themeService = themeService;
|
||||
_templateEngine = templateEngine;
|
||||
_viewRenderer = viewRenderer;
|
||||
_navBuilder = navBuilder;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the themed shell of the page, wrapping the page section in the layout template of the active theme.
|
||||
/// </summary>
|
||||
/// <param name="page">The rendered page section to wrap.</param>
|
||||
/// <param name="requestedThemeId">The optional unique identifier of the theme to render with, falling back to the current theme when <see langword="null"/>.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the full page HTML, or an error.</returns>
|
||||
public virtual async Task<Result<string>> RenderAsync(ThemeLayoutPageDto page, string? requestedThemeId = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ThemeRenderDocumentDto layoutDocument = await _themeService.GetRenderDocumentAsync(LAYOUT_PAGE_KEY, requestedThemeId, cancellationToken);
|
||||
string themeId = layoutDocument.Theme.Id;
|
||||
bool isAuthenticated = _httpContextAccessor.HttpContext?.User.Identity?.IsAuthenticated == true;
|
||||
|
||||
string appHead = await _viewRenderer.RenderPartialAsync("_ThemeLayoutHead", cancellationToken);
|
||||
string nav = await RenderNavAsync(themeId, cancellationToken);
|
||||
string audioPlayer = isAuthenticated ? await _viewRenderer.RenderPartialAsync("_AudioPlayer", cancellationToken) : string.Empty;
|
||||
string appScripts = await _viewRenderer.RenderPartialAsync("_ThemeLayoutScripts", cancellationToken);
|
||||
|
||||
ThemeLayoutModelDto layoutModel = new(
|
||||
page.Title,
|
||||
$"/theme-assets/{themeId}/assets",
|
||||
appHead,
|
||||
nav,
|
||||
page.Content,
|
||||
audioPlayer,
|
||||
appScripts,
|
||||
page.Script,
|
||||
isAuthenticated ? string.Empty : "bottom: 0px;");
|
||||
|
||||
Result<ThemePageRenderResultDto> renderResult = _templateEngine.RenderPage(layoutDocument.Template, layoutModel);
|
||||
if (renderResult.IsFailure)
|
||||
return renderResult.Errors;
|
||||
|
||||
return renderResult.Value.Content;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the navigation menu of the active theme, falling back to the application Razor menu when the theme template cannot be rendered.
|
||||
/// </summary>
|
||||
/// <param name="themeId">The manifest id of the active theme.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The rendered navigation menu HTML.</returns>
|
||||
private async Task<string> RenderNavAsync(string themeId, CancellationToken cancellationToken)
|
||||
{
|
||||
ThemeNavMenuDto navModel = await _navBuilder.BuildAsync(cancellationToken);
|
||||
ThemeRenderDocumentDto navDocument = await _themeService.GetRenderDocumentAsync(NAV_PAGE_KEY, themeId, cancellationToken);
|
||||
Result<ThemePageRenderResultDto> navRenderResult = _templateEngine.RenderPage(navDocument.Template, navModel);
|
||||
if (navRenderResult.IsSuccess)
|
||||
return navRenderResult.Value.Content;
|
||||
|
||||
return await _viewRenderer.RenderPartialAsync("_NavMenu", cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Authorization;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Enums.Authorization;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Common.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Claims;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Builds the navigation menu model for the themed navigation template, resolving the authorization conditions and localized labels server side.
|
||||
/// </summary>
|
||||
public sealed class ThemeNavBuilder
|
||||
{
|
||||
// the resource base name deliberately excludes the "Core.Resources" segment: the localization factory re-roots it with the configured ResourcesPath
|
||||
private const string VIEW_RESOURCE_BASE_NAME = "Lumina.Presentation.Web.Views.Shared._NavMenu";
|
||||
private const string VIEW_RESOURCE_LOCATION = "Lumina.Presentation.Web";
|
||||
|
||||
private readonly IUrlService _urlService;
|
||||
private readonly IStringLocalizerFactory _stringLocalizerFactory;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IStringLocalizer _localizer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ThemeNavBuilder"/> class.
|
||||
/// </summary>
|
||||
/// <param name="urlService">Injected service for generating URLs from action and controller names, with localization.</param>
|
||||
/// <param name="stringLocalizerFactory">Injected factory used to create the localizer of the navigation resources.</param>
|
||||
/// <param name="authorizationService">Injected service used to resolve the roles and permissions of the current user.</param>
|
||||
/// <param name="httpContextAccessor">Injected accessor for the current HTTP context.</param>
|
||||
public ThemeNavBuilder(IUrlService urlService, IStringLocalizerFactory stringLocalizerFactory, IAuthorizationService authorizationService, IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_urlService = urlService;
|
||||
_stringLocalizerFactory = stringLocalizerFactory;
|
||||
_authorizationService = authorizationService;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_localizer = stringLocalizerFactory.Create(VIEW_RESOURCE_BASE_NAME, VIEW_RESOURCE_LOCATION);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the navigation menu model for the current user and request.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The navigation menu model, with the sections visible to the current user.</returns>
|
||||
public async Task<ThemeNavMenuDto> BuildAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
ClaimsPrincipal user = _httpContextAccessor.HttpContext?.User ?? new ClaimsPrincipal();
|
||||
bool isAuthenticated = user.Identity?.IsAuthenticated == true;
|
||||
bool isAdmin = isAuthenticated && await _authorizationService.IsInRoleAsync("Admin", cancellationToken).ConfigureAwait(false);
|
||||
bool canCreateLibraries = isAuthenticated && (isAdmin || await _authorizationService.HasPermissionAsync(AuthorizationPermission.CanCreateLibraries, cancellationToken).ConfigureAwait(false));
|
||||
string returnUrl = Uri.EscapeDataString(GetCurrentRequestUrl());
|
||||
ThemeNavEntryDto[] languages = CreateLanguageEntries(returnUrl);
|
||||
|
||||
List<ThemeNavSectionDto> mobileSections = [];
|
||||
mobileSections.Add(CreateSiteSection());
|
||||
mobileSections.Add(CreateAccountSection(isAuthenticated));
|
||||
if (isAdmin)
|
||||
mobileSections.Add(CreateAdministratorSection());
|
||||
if (isAuthenticated)
|
||||
mobileSections.Add(CreateLibrarySection(canCreateLibraries));
|
||||
mobileSections.Add(new ThemeNavSectionDto(Localize("Language"), languages));
|
||||
if (isAuthenticated)
|
||||
mobileSections.Add(CreateToolsSection(isAuthenticated, languages: []));
|
||||
mobileSections.Add(CreateHelpSection());
|
||||
|
||||
List<ThemeNavSectionDto> menubarSections = [];
|
||||
menubarSections.Add(CreateSiteSection());
|
||||
menubarSections.Add(CreateAccountSection(isAuthenticated));
|
||||
if (isAdmin)
|
||||
menubarSections.Add(CreateAdministratorSection());
|
||||
if (isAuthenticated)
|
||||
menubarSections.Add(CreateLibrarySection(canCreateLibraries));
|
||||
menubarSections.Add(CreateToolsSection(isAuthenticated, languages));
|
||||
menubarSections.Add(CreateHelpSection());
|
||||
|
||||
return new ThemeNavMenuDto("Lumina", mobileSections, menubarSections);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the site section, which links to the home page.
|
||||
/// </summary>
|
||||
/// <returns>The site section of the navigation menu.</returns>
|
||||
private ThemeNavSectionDto CreateSiteSection()
|
||||
{
|
||||
return new ThemeNavSectionDto(
|
||||
"Lumina",
|
||||
[new ThemeNavEntryDto(Localize("Home"), _urlService.GetAbsoluteUrl(WebRoutes.Home.INDEX_CULTURED), "nav-link", [])]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the account section, whose entries depend on the authentication state of the user.
|
||||
/// </summary>
|
||||
/// <param name="isAuthenticated">Whether the current user is authenticated.</param>
|
||||
/// <returns>The account section of the navigation menu.</returns>
|
||||
private ThemeNavSectionDto CreateAccountSection(bool isAuthenticated)
|
||||
{
|
||||
List<ThemeNavEntryDto> items = [];
|
||||
if (isAuthenticated)
|
||||
{
|
||||
items.Add(new ThemeNavEntryDto(Localize("Logout"), _urlService.GetAbsoluteUrl(WebRoutes.Authentication.LOGOUT), CssClass: null, Children: []));
|
||||
items.Add(new ThemeNavEntryDto(Localize("Register"), _urlService.GetAbsoluteUrl(WebRoutes.Authentication.REGISTER_VIEW), "nav-link", []));
|
||||
items.Add(new ThemeNavEntryDto(Localize("ChangePassword"), _urlService.GetAbsoluteUrl(WebRoutes.Authentication.CHANGE_PASSWORD_VIEW), "nav-link", []));
|
||||
items.Add(new ThemeNavEntryDto(Localize("Profile"), _urlService.GetAbsoluteUrl(WebRoutes.Authentication.PROFILE_VIEW), "nav-link", []));
|
||||
}
|
||||
else
|
||||
{
|
||||
items.Add(new ThemeNavEntryDto(Localize("Login"), _urlService.GetAbsoluteUrl(WebRoutes.Authentication.LOGIN_VIEW), CssClass: null, Children: []));
|
||||
items.Add(new ThemeNavEntryDto(Localize("RecoverPassword"), _urlService.GetAbsoluteUrl(WebRoutes.Authentication.RECOVER_PASSWORD_VIEW), CssClass: null, Children: []));
|
||||
}
|
||||
|
||||
return new ThemeNavSectionDto(Localize("Account"), items);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the administrator section, shown only to administrators.
|
||||
/// </summary>
|
||||
/// <returns>The administrator section of the navigation menu.</returns>
|
||||
private ThemeNavSectionDto CreateAdministratorSection()
|
||||
{
|
||||
return new ThemeNavSectionDto(
|
||||
Localize("Administrator"),
|
||||
[
|
||||
new ThemeNavEntryDto(Localize("ManageRoles"), _urlService.GetAbsoluteUrl(WebRoutes.Admin.MANAGE_ROLES), "nav-link", []),
|
||||
new ThemeNavEntryDto(Localize("ManagePermissions"), _urlService.GetAbsoluteUrl(WebRoutes.Admin.MANAGE_PERMISSIONS), "nav-link", []),
|
||||
new ThemeNavEntryDto(Localize("Plugins"), _urlService.GetAbsoluteUrl(WebRoutes.Plugins.INDEX), "nav-link", [])
|
||||
]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the library section, shown only to authenticated users.
|
||||
/// </summary>
|
||||
/// <param name="canCreateLibraries">Whether the current user can create media libraries.</param>
|
||||
/// <returns>The library section of the navigation menu.</returns>
|
||||
private ThemeNavSectionDto CreateLibrarySection(bool canCreateLibraries)
|
||||
{
|
||||
List<ThemeNavEntryDto> items =
|
||||
[
|
||||
new ThemeNavEntryDto(Localize("ManageLibraries"), _urlService.GetAbsoluteUrl(WebRoutes.LibraryManagement.INDEX), "nav-link", [])
|
||||
];
|
||||
if (canCreateLibraries)
|
||||
items.Add(new ThemeNavEntryDto(Localize("AddNewLibrary"), _urlService.GetAbsoluteUrl(WebRoutes.LibraryManagement.ADD_LIBRARY), "nav-link", []));
|
||||
items.Add(new ThemeNavEntryDto(Localize("WrittenContent"), Url: null, CssClass: null,
|
||||
[
|
||||
new ThemeNavEntryDto(Localize("Books"), "library/written-content-library/books-library/books", "nav-link", []),
|
||||
new ThemeNavEntryDto(Localize("Magazines"), "library/written-content/magazines", "nav-link", [])
|
||||
]));
|
||||
items.Add(new ThemeNavEntryDto(Localize("Audio"), Url: null, CssClass: null,
|
||||
[
|
||||
new ThemeNavEntryDto(Localize("Music"), "library/audio/music", "nav-link", []),
|
||||
new ThemeNavEntryDto(Localize("Interviews"), "library/audio/interviews", "nav-link", [])
|
||||
]));
|
||||
items.Add(new ThemeNavEntryDto(Localize("Video"), Url: null, CssClass: null,
|
||||
[
|
||||
new ThemeNavEntryDto(Localize("Movies"), "library/video/movies", "nav-link", []),
|
||||
new ThemeNavEntryDto(Localize("TvShows"), "library/video/tvshows", "nav-link", [])
|
||||
]));
|
||||
|
||||
return new ThemeNavSectionDto(Localize("Library"), items);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the tools section, with the language submenu and the settings entry.
|
||||
/// </summary>
|
||||
/// <param name="isAuthenticated">Whether the current user is authenticated.</param>
|
||||
/// <param name="languages">The language entries of the submenu.</param>
|
||||
/// <returns>The tools section of the navigation menu.</returns>
|
||||
private ThemeNavSectionDto CreateToolsSection(bool isAuthenticated, IReadOnlyList<ThemeNavEntryDto> languages)
|
||||
{
|
||||
List<ThemeNavEntryDto> items = [];
|
||||
if (languages.Count > 0)
|
||||
items.Add(new ThemeNavEntryDto(Localize("Language"), Url: null, CssClass: null, Children: languages));
|
||||
if (isAuthenticated)
|
||||
items.Add(new ThemeNavEntryDto(Localize("Settings"), _urlService.GetAbsoluteUrl(WebRoutes.Settings.INDEX), "nav-link", []));
|
||||
|
||||
return new ThemeNavSectionDto(Localize("Tools"), items);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the help section.
|
||||
/// </summary>
|
||||
/// <returns>The help section of the navigation menu.</returns>
|
||||
private ThemeNavSectionDto CreateHelpSection()
|
||||
{
|
||||
return new ThemeNavSectionDto(
|
||||
Localize("Help"),
|
||||
[
|
||||
new ThemeNavEntryDto(Localize("Documentation"), "help/documentation", "nav-link", []),
|
||||
new ThemeNavEntryDto(Localize("About"), "help/about", "nav-link", [])
|
||||
]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the language entries of the navigation menu, each keeping the current request URL as the return URL.
|
||||
/// </summary>
|
||||
/// <param name="returnUrl">The encoded current request URL used as the return URL.</param>
|
||||
/// <returns>The language entries of the navigation menu.</returns>
|
||||
private ThemeNavEntryDto[] CreateLanguageEntries(string returnUrl)
|
||||
{
|
||||
string baseUrl = _urlService.GetAbsoluteUrl(WebRoutes.Language.SET_LANGUAGE) ?? string.Empty;
|
||||
(string Culture, string DisplayName)[] cultures =
|
||||
[
|
||||
("zh-cn", "简体中文"),
|
||||
("de-de", "Deutsch"),
|
||||
("en-us", "English"),
|
||||
("es-es", "Español"),
|
||||
("fr-fr", "Français"),
|
||||
("it-it", "Italiano"),
|
||||
("ja-jp", "日本語"),
|
||||
("ro-ro", "Română"),
|
||||
("ru-ru", "Русский")
|
||||
];
|
||||
|
||||
ThemeNavEntryDto[] entries = new ThemeNavEntryDto[cultures.Length];
|
||||
for (int index = 0; index < cultures.Length; index++)
|
||||
{
|
||||
(string culture, string displayName) = cultures[index];
|
||||
entries[index] = new ThemeNavEntryDto(displayName, $"{baseUrl}?newCulture={culture}&returnUrl={returnUrl}", "lang-set", []);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path and query string of the current request.
|
||||
/// </summary>
|
||||
/// <returns>The path and query string of the current request.</returns>
|
||||
private string GetCurrentRequestUrl()
|
||||
{
|
||||
HttpRequest request = _httpContextAccessor.HttpContext?.Request ?? throw new InvalidOperationException("The current HTTP context is unavailable.");
|
||||
return $"{request.Path}{request.QueryString}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves a localized navigation label.
|
||||
/// </summary>
|
||||
/// <param name="key">The resource key of the label.</param>
|
||||
/// <returns>The localized label.</returns>
|
||||
private string Localize(string key)
|
||||
{
|
||||
return _localizer[key].Value;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user