1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Role Manager feature has not been enabled?

Role Manager feature has not been enabled?

5 posts, 0 answered
  1. Doug
    Doug avatar
    34 posts
    Registered:
    20 Sep 2010
    11 Jan 2011
    Link to this post
    Hey all,

    I am not sure how to resolve this. I am attempting to do the following in code:
    string[] roles = Roles.GetRolesForUser("someuser");

    I am currently getting this error: 'The Role Manager feature has not been enabled'. Now, I realize that I probably need to add <roleManger> to my web.config file. So at the moment, I believe I understand what the problem is, but not really sure how to implement it.

    Here is what I have:
    <roleManager enabled="true" cacheRolesInCookie="true" defaultProvider="Default">
         <providers>
              <clear />
              <add name="Default" type="Telerik.Sitefinity.Security.Data.SitefinityRoleProvider, Telerik.Sitefinity" />
         </providers>
    </roleManager>

    I don't believe the type of I have specified is correct.

    Questions are:

    What is the type I need to use for the default role provider?
    Are there more attributes I need to specify on the add tag in providers?
    Is there anything else within the web.config that I need to modify or add to get this to work?

    Thanks,
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    11 Jan 2011
    Link to this post
    Hello Doug,

    You have to use Telerik.Sitefinity.Security.RoleManager. Sitefinity 4.0 does no read the data from the root web.config. It uses custom providers and custom config files.


    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());


    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Doug
    Doug avatar
    34 posts
    Registered:
    20 Sep 2010
    11 Jan 2011
    Link to this post
    Ok.

    At the moment, I'm having a different issue that was not coming up before.

    Here is the code I now have:
    // Get Membership User
    MembershipUser user = Membership.GetUser(UserNameTextBox.Text, true);
     
    // Get Sitefinity role manager
    var roleManager = RoleManager.GetManager();
     
    // Get all roles
    var roles roleManager.GetRoles();
     
    // Get all roles for a particular user
    var rolesForUser = roleManager.GetRolesForUser((Guid)user.ProviderUserKey);
     
    // Putting this into a string for simple testing and spitting out to an asp:Label
    string strRoles = string.Empty;
     
    int i = 0;
    foreach (Role role in rolesForUser)
    {
         bool printComma = i != rolesForUser.Count() - 1;
         strRoles += role.ToString();
         strRoles += printComma ? ", " : string.Empty;
     
         i++;
    }
     
    string data = string.Format("user info user: {0}, creation date: {1}, roles: {2}", user.UserName, user.CreationDate.ToString(), strRoles);
    LabelDisplay.Text = data;

    Now at the moment, I'm getting this error:
    'You are not authorized to 'Manage Users' ('Backend').'
    However, I am logged in as admin to sitefinity.

    Any thoughts.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    12 Jan 2011
    Link to this post
    Hi Doug,

    I checked this in the RC2 and if you are logged in as a backend user that has rights to manage roles and users there are no problem to work with the code. Please check the roles for your user and its permissions. You can also try this on a clean installation.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Doug
    Doug avatar
    34 posts
    Registered:
    20 Sep 2010
    13 Jan 2011
    Link to this post
    Ok, I got it to work. I had forgotten to log in which is why I saw that exception message.
5 posts, 0 answered