.NET 3.5以降を使用している場合は、System.DirectoryServices.AccountManagement
(S.DS.AM)名前空間を確認する必要があります。ここでそれについてすべて読んでください:
基本的に、ドメインコンテキストを定義して、AD内のユーザーやグループを簡単に見つけることができます。
// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// find a user
UserPrincipal user = UserPrincipal.Current; // this would be John Smith
if(user != null)
{
// get the user's groups he's a member of
PrincipalSearchResult<Principal> results = user.GetAuthorizationGroups();
// now you just need to iterate over the groups and see if you find the
// one group you're interested in
}
GetAuthorizationGroups
S.DS.AMでの呼び出しは、実際に再帰的なクエリを実行します。たとえば、グループが他のグループのメンバーであるため、ユーザーがメンバーになっているグループも取得します。
新しいS.DS.AMを使用すると、ADのユーザーやグループを簡単に操作できます。