//create role await roleManager.CreateAsync(new IdentityRole("admin")); //assign role to user await userManager.AddToRoleAsync(user, "admin"); //check if user has role if (await userManager.IsInRoleAsync(user, "admin")) { //perform admin actions }
//define roles var roles = new ListPackage/library: ASP.NET Core Identity, SimpleAuthorization.{ new Role("admin"), new Role("user"), }; //check if user is authorized if (User.HasRole("admin")) { //perform admin actions }