具有模拟或高权限的SharePoint C#运行代码

时间:2019-04-10 11:25:28

标签: c# sharepoint impersonation elevated-privileges

我有以下方法,但无法运行方法roleAssignments.GetUserWithReadPermissionOnly()

private string GetAccessXml(SPRoleAssignmentCollection roleAssignments, out string originalAccess)
{

    //Error at the following line
    var list = roleAssignments.GetUserWithReadPermissionOnly();

    var entries = "<Entities Append=\"False\" Error=\"\" Separator=\";\" MaxHeight=\"3\">{0}</Entities>";
    var entryTemplate = "<Entity Key=\"{0}\" DisplayText=\"{1}\" IsResolved=\"True\" Description=\"{0}\"><MultipleMatches /></Entity>";
    var entryBuilder = new StringBuilder();
    var csv = new StringBuilder();

    foreach (var principal in list)
    {
        var entry = entryTemplate;
        entryBuilder.AppendFormat(entry, principal.LoginName, principal.Name);
        csv.Append(principal.LoginName).Append(",");
    }
    originalAccess = csv.ToString().TrimEnd(',');
    return entries.FormatWith(entryBuilder);
}

我可以知道如何修改代码以使用ImpersonationElevatedRights运行该方法吗?


错误日志:

  

试图执行未经授权的操作。在   Microsoft.SharePoint.Utilities.SPUtility.HandleAccessDenied(Exception   例如)   Microsoft.SharePoint.SPSecurableObject.CheckPermissions(SPBasePermissions   在(PermissionMask)   Microsoft.SharePoint.SPRoleAssignmentCollection.Init()在   Microsoft.SharePoint.SPBaseCollection.GetEnumerator()在   MUU.NLB.ERMS.Mensa.CommonLibrary.PermissionLookup。<> c__DisplayClass5_0.b__0()   在   Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated   secureCode)   Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback   secureCode,对象参数)   Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated   secureCode)   ERMS.Mensa.CommonLibrary.PermissionLookup.GetUserWithReadPermissionOnly(SPRoleAssignmentCollection   角色分配)   ERMS.Admin.SystemSetting.FolderAccessControl.FolderAccessControlUserControl.GetAccessXml(SPRoleAssignmentCollection   roleAssignments,String和originalAccess)位于   ERMS.Admin.SystemSetting.FolderAccessControl.FolderAccessControlUserControl.GetFormattedNode(SPList   FilePlanList,SPFolder文件夹)位于   ERMS.Admin.SystemSetting.FolderAccessControl.FolderAccessControlUserControl.GetChildNodes(RadTreeNodeEventArgs   e)       异常数据:[FolderAccessControl] GetFormattedNode:FilePlanList = FilePlan [FolderAccessControl] GetFormattedNode:   文件夹= HP1-HA2-A0001

0 个答案:

没有答案