skip to Main Content

My Blazor Server app is working fine BUT it seems to remember the last user who logged in (using Windows AD) and thinks everyone afterwards is that user. Subsequent users do not get asked to log in. As I understand it, Server App does not use cookies but it obviously has some sort of cache to remember a user. How do I force it to Authorize every new user making a request?

Using ‘Authentication Type: Windows’ for the project and this code in program.cs:

builder.Services.AddAuthentication(
    NegotiateDefaults.AuthenticationScheme).AddNegotiate();
builder.Services.AddAuthorization(options =>
{
   options.FallbackPolicy = new 
      AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
});

This is the code which always returns the last logged in user:

var authState = await 
   AuthenticationStateProvider.GetAuthenticationStateAsync();

2

Answers


  1. I think you might have the above code in the shared folder that will cause the logged user issues.
    Follow these steps to resolve the issue.

    1. Create a new service and call the getusername() function.
    2. Then call that service in your razor.cs file to retrieve username.
    Login or Signup to reply.
  2. 1.Create a new folder in your project &
    Create a new class file and have the following code
    ADAuthService

    2.In your razor page, call the ADAuthservice in OnInitializedAsync() function.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search