Mohammed Syam
Mohammed Syam

Reputation: 525

Sitecore Item Access Rights

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

Answers (2)

Jan Bluemink
Jan Bluemink

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

Martin Davies
Martin Davies

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

Related Questions