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

ServerAuthenticationStateProvider: GetAuthenticationStateAsync was called before SetAuthenticationState

$
0
0

I am trying to use the ServerAuthenticationStateProvider in my current project, since we are using Blazor Server. Before we just used the base AuthenticationStateProvider, which also seems to work with Windows Identity. ServerAuthenticationStateProvider does not work properly though.

I register the provider in Program.cs

builder.Services.AddServerSideBlazor();builder.Services.AddScoped<ServerAuthenticationStateProvider>();

In my components (*.razor.cs) I use it like this:

[Inject] public ServerAuthenticationStateProvider AuthenticationStateProvider { get; set; } = default!;

But this throws an exception when accessing the page with a component:

System.InvalidOperationException: GetAuthenticationStateAsync was called before SetAuthenticationState.  at Microsoft.AspNetCore.Components.Server.ServerAuthenticationStateProvider.GetAuthenticationStateAsync()

I am not sure why this error happens. The Microsoft docs are also not clear on how to use this ServerAuthenticationStateProvider, so it might be doing something 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>