Answer the question
In order to leave comments, you need to log in
How to make [Authorize(Roles = "Administrator")] work?
I have an MVC web application. Made a reconstruction of the database model as stated in the article: https://docs.microsoft.com/en-us/ef/core/get-start... Reconstructed the tables: AspNetUsers, AspNetUserRoles, AspNetRoles. I created views for them to add, edit, delete, view details. Everything is added and edited. But when you try to set [Authorize(Roles = "Administrator")], the program does not let a single user in, although such a role is in the database and the relationship between the role ID and user ID is also written in the table, while if you leave [Authorize] then everything works , i.e. The user passes the authorization check successfully. But that's why it does not see the distribution of roles. As I understand it, it needs to be registered somewhere, but where and how I will not put my mind to it. What should I do?
Answer the question
In order to leave comments, you need to log in
I asked myself, I answered...
services.AddDefaultIdentity<IdentityUser>()
.AddRoles<IdentityRole>()
.AddDefaultUI(UIFramework.Bootstrap4)
.AddEntityFrameworkStores<ApplicationDbContext>();
.AddRoles<IdentityRole>()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question