Hi 929Free,
Thank you for reaching out to Microsoft Q & A forum.
The error (No authenticationScheme was specified) occurs because your Blazor application hasn't been configured with a default authentication scheme. Even when using a custom AuthenticationStateProvider, Blazor requires an authentication scheme to properly handle role-based authorization and redirection.
1.In your Program.cs file, register an authentication scheme. If you’re using cookie-based authentication, you can configure it like this:
builder.Services.AddAuthentication("MyCookieAuth")
.AddCookie("MyCookieAuth", options =>
{
options.LoginPath = "/login"; // Adjust to match your login route
});
builder.Services.AddAuthorization();
Also, make sure the authentication and authorization middleware is added in the correct order:
app.UseAuthentication();
app.UseAuthorization();
With this setup, your application will be able to redirect unauthenticated users to the login page and enforce role-based access as expected.
If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.