Role Manager feature has not been enabled?
Hey all,
I am not sure how to resolve this. I am attempting to do the following in code:
string
[] roles = Roles.GetRolesForUser(
"someuser"
);
<
roleManager
enabled
=
"true"
cacheRolesInCookie
=
"true"
defaultProvider
=
"Default"
>
<
providers
>
<
clear
/>
<
add
name
=
"Default"
type
=
"Telerik.Sitefinity.Security.Data.SitefinityRoleProvider, Telerik.Sitefinity"
/>
</
providers
>
</
roleManager
>
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
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;
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
Ok, I got it to work. I had forgotten to log in which is why I saw that exception message.