4

Is there any way from an API level to obtain a list of roles which are "base" roles from an existing Role object? i.e. the roles which would grant inherited read access?

I've noticed that when querying a users roles via

Sitecore.Context.User.Roles

these inherited or "base" roles are not listed.

7

If you need to get a base roles for role, you can use the GetRolesForRole(Role role, bool includeIndirectMembership) method of RolesInRolesManager.

For example, if you need to get a base roles for each role of user, you can use something like below:

foreach (var role in Sitecore.Context.User.Roles)
{
    var basedRoldes = RolesInRolesManager.GetRolesForRole(role, true);
}

The RolesInRolesManager is defined at the Sitecore.Security.Accounts namespace.

If includeIndirectMembership flag is false, the method will return just a base roles for role. If flag is true, the method will also return a base roles of each base role.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.