Mart Apon
Mart Apon

Reputation: 119

Blazor Server app with cookie authentication - Roles not working

I have a Blazor server app, I implemented cookie auth as shown in: https://www.pragimtech.com/blog/blazor/asp.net-core-identity-setup-in-blazor-application/

I can succesfully protect my page with <AuthorizeView> and @attribute [Authorize]. But I cant get my roles to work, when I use for example: @attribute [Authorize (Roles = "Installer"] it keeps telling me "Not authorized".

The user and the roles are present in the database (it works with my Blazor WASM project with individual user auth) so I think that cant be the problem.

Did anyone encoutered this problem before??

Upvotes: 0

Views: 709

Answers (1)

enet
enet

Reputation: 45664

Do you have something similar to this in your Startup class:

services.AddDefaultIdentity<ApplicationUser>(options => 
     options.SignIn.RequireConfirmedAccount = false)
    .AddRoles<IdentityRole>()
    .AddEntityFrameworkStores<ApplicationDbContext>(); 

Upvotes: 2

Related Questions