Reputation: 525
I want to check if a sitecore item has any access rights applied or not so I am thinking of checking if the security field has a value i.e
item.Fields["__Security"].Value
Is this is the correct way of checking if an item has access rights or Is there another way of doing this?
Upvotes: 4
Views: 489
Reputation: 3487
Yes, in the __Security Field are the rights stored.
You can use: item.Security.GetAccessRules();
var accessRules = item.Security.GetAccessRules();
if (accessRules != null)
{
foreach (var rule in accessRules)
{
var name = rule.Account.Name;
var comment = rule.AccessRight.Comment;
var permiss = rule.SecurityPermission;
}
}
Upvotes: 5
Reputation: 4456
This sort of thing feels more more API-ish
foreach(Role role in RolesInRolesManager.GetAllRoles())
{
bool hasReadAccess= itemUnderTest.Security.CanRead(role);
}
In fact, take a look at all the methods of Item.Security
Upvotes: 2