2010-07-01 60 views

回答

2

未經測試的代碼,但類似的東西。

這同時適用於組和用戶,也爲所有的權限(項,列表網等)

public static bool DoesPrincipalHavePermission(ISecurableObject @object, SPPrincipal principal, SPRoleDefinition role) 
{ 
     var assignment = @object.RoleAssignments.GetAssignmentByPrincipal(principal); 
     if (assignment == null || assignment.RoleDefinitionBindings.Count < 1) 
      return false; 

     foreach (SPRoleDefinition r in assignment.RoleDefinitionBindings) 
     { 
      if (r.BasePermissions == role.BasePermissions) 
       return true; 
     } 

     return false; 
}