0

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??

Mart Apon
  • 69
  • 1
  • 1
  • 8

1 Answers1

2

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

services.AddDefaultIdentity<ApplicationUser>(options => 
     options.SignIn.RequireConfirmedAccount = false)
    .AddRoles<IdentityRole>()
    .AddEntityFrameworkStores<ApplicationDbContext>(); 
enet
  • 41,195
  • 5
  • 76
  • 113
  • That was the trick, I first looked in my startup.cs but I use cookie auth so I had to put the .Addroles in my IdentityHostingStartup class. – Mart Apon Nov 29 '21 at 12:38