1

このコードは適切ではありません:

web.IsCurrentUserMemberOfGroup(web.Groups["Namegruop"].ID);
4

1 に答える 1

3

AD セキュリティ グループメンバーシップとSharePoint グループメンバーシップを区別する必要があります。

AD セキュリティ メンバーシップを確認するには、 を使用できますSystem.Security.Principal.WindowsPrincipal.IsInRole。SharePoint API を使用する必要はありません。

using(WindowsIdentity identity = WindowsIdentity.GetCurrent())
{
  WindowsPrincipal p = new WindowsPrincipal(identity);
  if (p.IsInRole("DOMAIN\\GroupName")) // Alternative overloads with SecurityIdentifier available
  {
    // ...
  } 
}

現在のユーザーが SharePoint グループのメンバーであるかどうかを確認するには、SharePoint API を使用できます。

SPWeb web = // ...
SPGroup group = web.SiteGroups["GroupName"];
if (group.ContainsCurrentUser)
{
  // ...
}
于 2012-04-11T08:06:41.460 に答える