sitefinity | cms

Sitefinity Rookie Guide : Get Users in a Custom Role

To get users in a custom role, make sure to use the Role manager with Default Provider in Sitefinity.

Abhith Rajan
Abhith RajanOctober 21, 2017 ยท 1 min read ยท Last Updated:

I am pretty new to Sitefinity and started learning since one of the upcoming projects is need to be done in the Sitefinity.

Now spent few days in a POC, in which one requirement is to list users in a custom role that we created. And it can be achieved easily using below code,

1var roleMngr = RoleManager.GetManager("Default");
2var usersInCustomRole = roleMngr.GetUsersInRole("CustomRole");
3foreach (var user in usersInCustomRole)
4{
5 var userProfileManager = UserProfileManager.GetManager();
6 var sitefinityProfile = userProfileManager.GetUserProfile<SitefinityProfile>(user);
7
8 ...
9}

Replace the CustomRole with the role name which you have created, in my case, it was Reviewer. Since we want users in a custom role (i.e role which we created), we need to use the Default provider.

The custom roles you created are part of the Default Provider.

In case of built-in roles, use AppRoles as the provider name to get the role manager.

Abhith Rajan

Written by Abhith Rajan
Abhith Rajan is an aspiring software engineer with more than nine years of experience and has a proven successful track record of delivering technology-based products and services.
Connect

Was this helpful?

This page is open source. Noticed a typo? Or something unclear?
Improve this page on GitHub

Related ArticlesView All