Role Manager feature has not been enabled?

Posted by Community Admin on 03-Aug-2018 19:03

Role Manager feature has not been enabled?

All Replies

Posted by Community Admin on 11-Jan-2011 00:00

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,

Posted by Community Admin on 11-Jan-2011 00:00

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

Posted by Community Admin on 11-Jan-2011 00:00

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.

Posted by Community Admin on 12-Jan-2011 00:00

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

Posted by Community Admin on 13-Jan-2011 00:00

Ok, I got it to work. I had forgotten to log in which is why I saw that exception message.

This thread is closed