CRUD operations with roles

To manage roles, use the Telerik.Sitefinity.Security.RoleManager class. You can get an instance of the manager with the default roles data provider. However, this will not work with the out-of-the-box roles, such as Administrators, Editors, Authors, because they are coming from the AppRoles provider. So you must get an instance of the provider by passing the SecurityManager.ApplicationRolesProviderName as a parameter:

For more information, see For developers: Roles data providers.

Create roles

The following example creates a role.
First, you get an instance of the roles manager. Then, you create the role by calling the CreateRole method of the manager. Finally, you save the changes.

Query roles

You can query a role by:

  • ID
  • Name

Querying a role by ID

The following example queries for a role by its ID.
First, you get an instance of the roles manager. Then, you get all roles by calling the GetRoles method of the manager and filter based on the ID property.

Querying a role by name

The following example queries for a role by its name.
First, you get an instance of the roles manager. Then, you get all roles by calling the GetRoles method of the manager and filter based on the Name property.

Querying all roles

The following example queries for all roles
First, you get an instance of the roles manager. Then, you get all roles by calling the GetRoles method of the manager.

Modify roles

The following example modifies a role by changing its name.
To modify a role, you get an instance of the role. In this example, you get in instance of the role by its ID. For more information, see Query roles above. Then, you change the name and, finally, you save the changes.

Delete roles

The following example deletes a role.
To delete a role, you get an instance of the role. In this example, you get an instance of the role by its ID. For more information, see Query roles above. Then, you delete the role by calling the Delete method of the manager and passing the role as an argument. Finally, you save the changes.

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?

Next article

Roles data providers