Assigning Application Roles
Does anyone know how I can via the API assign a user the roles like "Editors" or "Authors"? "application roles – these are similar to user roles, but they are assigned to users automatically based on predefined conditions." Any help is most welcome. .a
Using the RoleManager.GetManager().GetRole("Editors") is not supported. So one can't call the AddUserToRole() method.
I can't find my way around the documentation and pinpoint the proper keyword to search for.
The one thing I keep hitting is this:
But no clues as to what those conditions are. I can set the roles via the GUI, but I need to do it through code.
Hello Anders,
Here is a sample code
RoleManager roleManager = RoleManager.GetManager(
"AppRoles"
);
roleManager.Provider.SuppressSecurityChecks =
true
;
var role = roleManager.GetRole(
"Administrators"
);
// or any other AppRole
roleManager.AddUserToRole(user, role);
roleManager.SaveChanges();
Thank you for a quick response!
.a