Reputation: 8295
I'm trying to test if items can be viewed by an anonymous user:
var anon = User.FromName("domain\\Anonymous");
if (item.Security.CanRead(anonymousUser))
return true;
But it always returns true, even when I know that for particular items, they must have a certain role to view it, as I can see from the access viewer:
Upvotes: 2
Views: 871
Reputation: 2635
The responsible crawler -which actually executes ComputeFieldValue code- is designed in such way to wrap this code in a SecurityDisabler. That is why it is not possible inside a computed field to verify whether has access to the field or not.
Sitecore does recommend to do the security check during the search (ootb) but indeed the TotalResults do not match if you do - which sucks ;)
If you would try to get security in the index - first try to find a solution for keeping the item security updated. E.g. if you would break inheritance somewhere, how would your index know what items to update? ...
Upvotes: 1