Display specific user's roles - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Display specific user's roles

  • Display specific user's roles
  • 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?

    Alex Lorenz
  • 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.