简体   繁体   English

从Active Directory获取用户角色/组 - mvc3

[英]Getting user roles/groups from Active Directory - mvc3

I need to be able to compare the users active directory groups against a list of acceptable groups. 我需要能够将用户活动目录组与可接受组列表进行比较。 This is not for authentication. 这不是用于身份验证。

I know i can use System.DirectoryServices but i have seen many posts that say to use AccountManagement but all i see is .Active Directory. 我知道我可以使用System.DirectoryServices,但我看到许多帖子说使用AccountManagement但我看到的只是.Active Directory。

Can anyone please assist me in the right direction? 谁能帮助我朝正确的方向发展?

Try something like this: check out the System.DirectoryServices.AccountManagement (S.DS.AM) namespace. 尝试这样的事情:查看System.DirectoryServices.AccountManagement (S.DS.AM)命名空间。 Read all about it here: 在这里阅读所有相关内容:

Basically, you can define a domain context and easily find users and/or groups in AD: 基本上,您可以定义域上下文并轻松查找AD中的用户和/或组:

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");

if(user != null)
{
   PrincipalSearchResult<Principal> authgroups = user.GetAuthorizationGroups();

   // do your checking with the auth groups that the user has - against your list 
}

The new S.DS.AM makes it really easy to play around with users and groups in AD! 新的S.DS.AM使得在AD中与用户和群组玩游戏变得非常容易!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM