public AuthenticationStateProvider AuthenticationStateProvider { get; set; }

var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();


private Task<AuthenticationState> AuthenticationStateTask { get; set; }

var user = (await AuthenticationStateTask).User;

AuthenticationStateProvider vs AuthenticationState

blazor authenticationstateprovider
  • Blazor has a built-in service called AuthenticationStateProvider service.
  • This service obtains authentication state data from ASP.NET Core’s HttpContext.User.
  • This is how authentication state integrates with existing ASP.NET Core authentication mechanisms.
  • It is this service that is used by AuthorizeView component and CascadingAuthenticationState component to get the authentication state.
  • Don’t use AuthenticationStateProvider directly. Use the AuthorizeView component.
  • The main drawback to using AuthenticationStateProvider directly is that the component isn’t notified automatically if the underlying authentication state data changes.


Last modified: December 26, 2020



Write a Reply or Comment