What is the best way to check if a user has permission to a site collection/site? I'm currently using the following
SPSecurity.RunWithElevatedPrivileges(
() => {using (var site = new SPSite(nodeUrl))
{
using (var web = site.OpenWeb())
{
retValue=
web.DoesUserHavePermissions(
context.User.Identity.Name,
SPBasePermissions.Open);
}
}
});
This doesn't seem to be working properly. If the user was never added to the site this works. But if the user was added and then removed DoesUserHavePermission(.. SPBasePermission.Open) still returns true, but when the user tries to access the site SharePoint throws the access denied page.
After a little more digging I found that the user account is still in the web.AllUsers list, but it has no Roles assigned.