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.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?

Next article

Roles data providers