したがって、このチュートリアルに従って、正常にログインできましたが、ユーザーがグループに属しているかどうかを確認しようとしていたため、次のことを試しました。
if (User.IsInRole("group"))
一緒に
enableSearchMethods="true"
何もうまくいかないようですが、おそらく私は間違った場所を見ているのです...誰かヒントがありますか?
したがって、このチュートリアルに従って、正常にログインできましたが、ユーザーがグループに属しているかどうかを確認しようとしていたため、次のことを試しました。
if (User.IsInRole("group"))
一緒に
enableSearchMethods="true"
何もうまくいかないようですが、おそらく私は間違った場所を見ているのです...誰かヒントがありますか?
.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.FindByIdentity(ctx, "SomeUserName");
if(user != null)
{
// do something here....
PrincipalSearchResult<Principal> groups = user.GetAuthorizationGroups();
// enumerate the groups found - check to find your group in question
}
新しい S.DS.AM を使用すると、AD でユーザーやグループを簡単に操作できます。
または、ユーザーとグループのプリンシパルを見つけることもできます。
// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");
GroupPrincipal groupToCheck = GroupPrincipal.FindByIdentity(ctx, "YourGroupNameHere");
if(user != null && groupToCheck != null)
{
// this call will tell you - yes or no - whether that user is member of that group
bool isMember = user.IsMemberOf(groupToCheck);
}