I am developing a Blazor Server application based on .NET 9 that uses ASP.NET Core Identity. The identity components (like ChangePassword
) are coming from the MudBlazor template. Now, for some reasone, when I navigate to /Account/Manage/ChangePassword
, my MudMenu
in the AppBar
doesn't open anymore. After navigation to back to Home it starts working again....
Things I have tried before.
- Added the
ProfileMenu
component to another site where it works. However, there it's not part of the AppBar anymore - Removing the outer
MudMenu
elements and only keepMudNavMenu
Even if I comment everything inside ChangePassword.razor
the issue persists, which makes me think the culprit is not the ChangePassword site itself, but somewhere else.
I am lost here... any help is much appreciated.
App.razor
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><base href="/"/><link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet"/><link href=@Assets["_content/MudBlazor/MudBlazor.min.css"] rel="stylesheet"/><ImportMap/><HeadOutlet @rendermode="PageRenderMode"/></head><body><Routes @rendermode="PageRenderMode"/><script src="_framework/blazor.web.js"></script><script src=@Assets["_content/Extensions.MudBlazor.StaticInput/NavigationObserver.js"]></script><script src=@Assets["_content/MudBlazor/MudBlazor.min.js"]></script></body></html>@code { [CascadingParameter] private HttpContext HttpContext { get; set; } = default!; private IComponentRenderMode? PageRenderMode => HttpContext.AcceptsInteractiveRouting() ? InteractiveServer : null;}
MainLayout.razor
@using MyApplication.Web.Components.Navbar@inherits LayoutComponentBase<MudThemeProvider/><MudPopoverProvider/><MudDialogProvider/><MudSnackbarProvider/><MudLayout><AppBar/><MudMainContent> @Body</MudMainContent></MudLayout>...
AppBar.razor
<MudAppBar Fixed="false"><MudStack Row="true" Justify="Justify.FlexEnd" AlignItems="AlignItems.Center" Style="width: 100%"> ... @if (IsAuthenticated) {<ProfileMenu/> }</MudStack></MudAppBar>@code { public bool IsAuthenticated { get; set; } [Inject] public AuthenticationStateProvider? AuthenticationStateProvider { get; set; } [Inject] public ILogger<AppBar> Logger { get; set; } protected override async Task OnInitializedAsync() { var state = await AuthenticationStateProvider?.GetAuthenticationStateAsync()!; IsAuthenticated = state.User.Identity!.IsAuthenticated; Logger.LogInformation($"Authentication state: {IsAuthenticated}"); }}
ProfileMenu.razor
<MudMenu StartIcon="@Icons.Material.Outlined.AccountCircle" Label="Mein Profil" FullWidth="true" Variant="Variant.Outlined" Color="Color.Tertiary"><MudNavMenu><MudNavLink Href="/favorites" Icon="@Icons.Material.Outlined.FavoriteBorder">Merkliste</MudNavLink><MudNavLink Href="/my-ads" Icon="@Icons.Material.Filled.PostAdd">Meine Inserate</MudNavLink><MudNavGroup Href="/Account/Manage" Title="Profile bearbeiten" Icon="@Icons.Material.Filled.Settings"><MudNavLink Href="/Account/Manage/ChangePassword" Icon="@Icons.Material.Outlined.Lock">Kennwort ändern</MudNavLink><MudNavLink Href="/Account/Manage/Email" Icon="@Icons.Material.Outlined.Mail">Mail Addresse ändern</MudNavLink></MudNavGroup><MudNavLink Href="/Account/Logout" Icon="@Icons.Material.Filled.Logout">Ausloggen</MudNavLink></MudNavMenu></MudMenu>
ChangePassword.razor
@page "/Account/Manage/ChangePassword"@using System.ComponentModel.DataAnnotations@using Microsoft.AspNetCore.Identity@using MyApplication.Infrastructure.Identity@using MyApplication.Web.Components.Layout@using MudBlazor.StaticInput@using MyApplication.Web.Components.Navbar@inject UserManager<ApplicationUser> UserManager@inject SignInManager<ApplicationUser> SignInManager@inject IdentityUserAccessor UserAccessor@inject IdentityRedirectManager RedirectManager@inject ILogger<ChangePassword> Logger<PageTitle>Change password</PageTitle><MudContainer MaxWidth="MaxWidth.Small"><MudText Typo="Typo.h6" GutterBottom="true">Kennwort ändern</MudText><EditForm Model="Input" FormName="change-password" OnValidSubmit="OnValidSubmitAsync" method="post"><DataAnnotationsValidator/><MudGrid><MudItem md="12"><MudStaticTextField For="@(() => Input.OldPassword)" @bind-Value="Input.OldPassword" Variant="_variant" InputType="InputType.Password" Label="Kennwort" Placeholder="Kennwort" HelperText="Bitte altes Kennwort eingeben." UserAttributes="@(new() { { "autocomplete", "current-password" }, { "aria-required", "true" } })"/></MudItem><MudItem md="12"><MudStaticTextField For="@(() => Input.NewPassword)" @bind-Value="Input.NewPassword" Variant="_variant" InputType="InputType.Password" Label="Neues Kennwort" Placeholder="Neues Kennwort" HelperText="Bitte neues Kennwort eingeben." UserAttributes="@(new() { { "autocomplete", "new-password" }, { "aria-required", "true" } })"/></MudItem><MudItem md="12"><MudStaticTextField For="@(() => Input.ConfirmPassword)" @bind-Value="Input.ConfirmPassword" Variant="_variant" InputType="InputType.Password" Label="Neues Kennwort" Placeholder="Kennwort bestätigen" HelperText="Bitte neues Kennwort erneut eingeben." UserAttributes="@(new() { { "autocomplete", "new-password" }, { "aria-required", "true" } })"/></MudItem><MudItem md="12"><MudStaticButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true" FormAction="FormAction.Submit"> Kennwort aktualisieren</MudStaticButton></MudItem><MudItem md="12"><StatusMessage Message="@message"/></MudItem></MudGrid></EditForm></MudContainer>@code { ...}