2

We need to show some items to some particular users on our website based on some security roles applied and need to show lock icons to other users. But in code behind we are getting null items, on those security is applied.

enter image description here

We are using below code to get item -

var searchItem = Sitecore.Context.Database.GetItem(itemId);

In above code we checked it by itemId and by item path as well, but still these security applied items are null, so can you please help me how can I get these items in code behind.

3

You can check in code behind like below -

var searchItem = Sitecore.Context.Database.GetItem(itemId);
if (searchItem == null)
{
    using (new Sitecore.SecurityModel.SecurityDisabler())
    {
       searchItem = Sitecore.Context.Database.GetItem(item.ItemId);
    }
}

And then you can check access on this item -

bool hasAccess = searchItem.Security?.CanRead(Sitecore.Context.User) ?? true;

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.