User Roles in Code
I am developing a custom user control for my Sitefinity application. It has a Rad Grid on it which is bound to data that will be dynamically retrieved in code.
The data needs to be retrieved based on what the user's roles are.
How can I get the current user's roles in code so I can retrieve the correct data.
Hello ,
There is a method of RoleManager - GetRolesForUser that you can use. You can use SecurityManager.GetCurrentUserId() to get the id of the current user.
Regards,
Ivan Dimitrov
the Telerik team
We just upgraded from build 1098 to build 1210
With respect to this code:
var roleMgr = new RoleManager();
var rolesForUser = roleMgr.GetRolesForUser(SecurityManager.GetCurrentUserId()).ToList();
Before the upgrade GetRolesForUser(), as used above, returned all the roles for the user.
Now (build 1210) GetRolesForUser(), as used above, does not return Administrators or BackendUsers.
Can you please verify this.
If what I am observing is correct, what method can I use to get all the user's roles?
Hi,
I see the same issue.
Besides, there are some other predefined roles like Authors, Editors, Designers that do not come back. So, when I check for existing roles and try to create a role if it does not exist, it creates additional role e.g. Editors, and I can assign users only to "MY" role but not to the role that came with Sitefinity.
Hello,
The method woks properly. Most probably you are not passing the correct provider to it
var userID = SecurityManager.GetCurrentUserId();
var manager = RoleManager.GetManager("AppRoles");
var roles = manager.GetRolesForUser(userID).ToList();
AppRoles is the provider used for the default roles like "Administrators"
Regards,
Ivan Dimitrov
the Telerik team