Hi @Bahavu Atosha ,
Generally, in asp.net core application, it will use the Asp.net core Identity to manager user and roles.
I assume you are also using Asp.net core Identity to manage user and role, if that is the case, you can add Role services to Identity using the following code:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>()
.AddRoles<IdentityRole>() // Append AddRoles to add Role services:
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddControllersWithViews();
services.AddRazorPages();
}
Or update the Identity service as below:
services.AddIdentity<IdentityUser, IdentityRole>()
// services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
Then, you can use the RoleManager to add/delete role, and use the UserManager to assign a role to the specified user(check the RoleManager and UserManager's methods). Here is an article about How to work with Roles in ASP.NET Core Identity, you could refer it.
Besides, if you want to add custom user data to the Identity table, you can refer Add, download, and delete custom user data to Identity in an ASP.NET Core project.
And here is an article about Role-based authorization in ASP.NET Core and Policy-Based And Role-Based Authorization In ASP.NET Core 3.0 Using Custom Handler, they might help you manage user privileges.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion