Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Getting ApplicationUser in BlazorServer page

$
0
0

I'm trying to access ApplicationUser of current logged-in user in Blazor Server .NET 8 app. I've added a new page in /Account/ISP called Index.razor

@page "/Account/ISP"@using Microsoft.AspNetCore.Identity@using WebApp.Components.Account.Shared@using WebApp.Data@inject UserManager<ApplicationUser> UserManager@inject SignInManager<ApplicationUser> SignInManager@inject IdentityUserAccessor UserAccessor@inject IdentityRedirectManager RedirectManager@inject ApplicationDbContext DbContext@code {    private ApplicationUser user = default!;    [CascadingParameter]    private HttpContext HttpContext { get; set; } = default!;    protected override async Task OnInitializedAsync()    {        user = await UserAccessor.GetRequiredUserAsync(HttpContext);    }}

Here I'm trying to replicate the logic of getting my user in Account/Manage, where it works nice from created Blazor template. After logging-in, I'm clicking the menu item to navigate to this page, and here I get NullReferenceException without stack trace. What did I do wrong?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>