Display specific user's roles

Posted by Community Admin on 05-Aug-2018 22:41

Display specific user's roles

All Replies

Posted by Community Admin on 16-Dec-2010 00:00

I am extending the user profile by storing this additional info in a separate table from sf_users.  By doing this I have created a custom control to manage this information and I would like to display the specific user's roles.  Here is the code that I have, but it does not seam to be populating with the correct data:

RoleManager roleManager = RoleManager.GetManager(RoleManager.GetDefaultProviderName());
IQueryable<Role> roles = roleManager.GetRolesForUser(user.Id);

Is this the correct way of "getting" the roles if i just loop through the "roles" collection?

Thanks,
Alex Lorenz

Posted by Community Admin on 16-Dec-2010 00:00

Hi Alex,

The code you have looks fine. Here are some notes that might help

RoleManager.GetManager("AppRoles") - returns built-in roles. There are predefined roles that are part of applicationRoles

var roleManager = RoleManager.GetManager("AppRoles");
 var roles = roleManager.GetRoles();

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

var rolesForUser = roleManager.GetRolesForUser(SecurityManager.GetCurrentUserId());



Best wishes,
Ivan Dimitrov
the Telerik team


Check out Telerik Trainer, the state of the art learning tool for Telerik products.

This thread is closed