Search code examples
asp.net-coreblazoridentity

.NET 8 Blazor with Microsoft Identity - Current User's Custom Properties


How do I get the current signed in user's custom properties that I have added? (Additional columns) I have done research but do not get answers on it. If I could get the user id I could perhaps write custom code for it.


Solution

  • Following code get current login user's name , and then find this user all information.

    @page "/"
    @using Microsoft.AspNetCore.Identity
    @inject AuthenticationStateProvider _authenticationStateProvider
    @inject UserManager<IdentityUser> _userManger
    
    @code{
        protected override async Task OnInitializedAsync(){
            var state=await _authenticationStateProvider.GetAuthenticationStateAsync();
            var username = state.User.Identity.Name;
            var userFullinfo =await _userManger.FindByNameAsync(username);
        }
    }