如何验证用户是否属于C#.NET中的Active Directory用户组
我正在编写代码来验证用户是否属于特定的广告组 当我检查组详细信息时,如下所示:如何验证用户是否属于C#.NET中的Active Directory用户组,c#,active-directory,C#,Active Directory,我正在编写代码来验证用户是否属于特定的广告组 当我检查组详细信息时,如下所示: "CN=Building - 28 (ALL),OU=Exchange Auto Groups,OU=AM,OU=schwab,DC=am,DC=corp,DC=schwab,DC=com" 这就是我要验证的用户(例如:user1)是否属于该组的组 我正在尝试使用返回用户所属组列表的方法。这里我必须根据组进行过滤 带出用户所属的active directory用户组的代码: private List<stri
"CN=Building - 28 (ALL),OU=Exchange Auto Groups,OU=AM,OU=schwab,DC=am,DC=corp,DC=schwab,DC=com"
这就是我要验证的用户(例如:user1)是否属于该组的组
我正在尝试使用返回用户所属组列表的方法。这里我必须根据组进行过滤
带出用户所属的active directory用户组的代码:
private List<string> GetUserGroupMembership(string userName)
{
var directoryEntry = new DirectoryEntry();
DirectorySearcher search = new DirectorySearcher();
**//filter based on the username**
search.Filter = String.Format("(cn={0})", userName);
**//How to filter based on the Group "CN=Building - 28 (ALL),OU=Exchange Auto Groups,OU=AM,OU=schwab,DC=am,DC=corp,DC=schwab,DC=com"**
search.PropertiesToLoad.Add("memberOf");
List<string> groupsList = new List<string>();
SearchResult result = search.FindOne();
if (result != null)
{
int groupCount = result.Properties["memberOf"].Count;
for (int counter = 0; counter < groupCount; counter++)
{
groupsList.Add((string)result.Properties["memberOf"][counter]);
}
}
return groupsList.ToList();
}
私有列表GetUserGroupMembership(字符串用户名)
{
var directoryEntry=新的directoryEntry();
DirectorySearcher search=新建DirectorySearcher();
**//根据用户名进行筛选**
search.Filter=String.Format(“(cn={0})”,用户名);
**//如何基于组“CN=Building-28(ALL)、OU=Exchange Auto Groups、OU=AM、OU=schwab、DC=AM、DC=corp、DC=schwab、DC=com”进行过滤**
search.PropertiesToLoad.Add(“memberOf”);
列表组列表=新列表();
SearchResult=search.FindOne();
如果(结果!=null)
{
int groupCount=result.Properties[“memberOf”].Count;
用于(int计数器=0;计数器
我感谢你的答复
如果您使用的是.NET 3.5或更高版本,请查看。这些课程非常容易使用。比如说,
PrincipalContext pc = new PrincipalContext(ContextType.Domain);
UserPrincipal user = UserPrincipal.FindByIdentity(pc, "johndoe");
var groups = user.GetAuthorizationGroups() // or user.GetUserGroups()
请看这些文章,其中给出了一些相同的概述:
如果您使用的是.NET 3.5或更高版本,请查看。这些课程非常容易使用。比如说,
PrincipalContext pc = new PrincipalContext(ContextType.Domain);
UserPrincipal user = UserPrincipal.FindByIdentity(pc, "johndoe");
var groups = user.GetAuthorizationGroups() // or user.GetUserGroups()
请看这些文章,其中给出了一些相同的概述:
如何避免有人伪造帐户名?如何避免有人伪造帐户名?