我在System Acoount中运行了一些SP-Code。但即使有这个用户,我仍然会收到拒绝接入的访问权限。我还尝试了其他用户帐户(具有管理员权限)
错误讯息:
Attempted to perform an unauthorized operation.
at Microsoft.SharePoint.SPGlobal.HandleUnauthorizedAccessException(UnauthorizedAccessException ex)
at Microsoft.SharePoint.SPSecurableObject.CheckPermissions(SPBasePermissions permissionMask)
at Microsoft.SharePoint.SPRoleAssignmentCollection.Init()
at Microsoft.SharePoint.SPBaseCollection.GetEnumerator()
at OLXPermissionEventReceiver.OLXPermissionEventReceiver.OLXPermissionEventReceiver.<>c__DisplayClass1.<SetPermissionsToListItem>b__0()
代码:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
try
{
SPSite tmpSite = new SPSite("Http://example.com);
SPUserToken sysUser = tmpSite.SystemAccount.UserToken;
using (SPSite site = new SPSite(siteUrl, sysUser))
{
using (SPWeb web = site.OpenWeb())
{
try
{
SPPrincipal principal = (SPPrincipal) group;
item.BreakRoleInheritance(false);
web.AllowUnsafeUpdates = true;
// Works until here
List<SPRoleAssignment> roleAssignmentList = new List<SPRoleAssignment>();
bool cateringRoleFound = false;
foreach (SPRoleAssignment roleAssignment in item.RoleAssignments)
{
}
}
}
}
}
}
看起来像“foreach” - 循环正在抛出错误。有什么想法吗?