DirectoryEntry deEntry = new DirectoryEntry("LDAP://test.com");
DirectorySearcher dsSearcher = new DirectorySearcher(deEntry);
dsSearcher.Filter = "(&(objectclass=user)(objectcategory=person))";
当我应用该过滤器时,用户不会显示。但我检查了他的属性,这些属性都有这些值。
但是当我在过滤器中添加他的姓氏时,他会出现。
dsSearcher.Filter = "(&(objectclass=user)(objectcategory=person)(sn=harper))";
这是带有deubg信息的图片,显示他的属性设置正确。
我不知道发生了什么。有什么想法吗?
答案 0 :(得分:1)
如果您使用的是.NET 3.5及更高版本,则应查看System.DirectoryServices.AccountManagement
(S.DS.AM)命名空间。在这里阅读所有相关内容:
基本上,您可以定义域上下文并轻松在AD中查找用户和/或组:
// set up domain context
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
{
// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "harper");
if(user != null)
{
// do something here....
}
}
新的S.DS.AM让您可以轻松地与AD中的用户和群组一起玩!