【发布时间】:2016-01-04 23:29:28
【问题描述】:
我有一个使用 Ldap 查询的组名称列表...我已将列表名称绑定到 WinForms 应用程序中的数据网格。当用户选择其中一个组名时,会触发一个事件并将组名传递给以下方法:-
// Get a list of group specific users //
private List<Users> GetUsers(string groupName)
{
List<Users> groupSpecificUsers = new List<Users>();
DirectorySearcher ds = null;
DirectoryEntry de = new DirectoryEntry(domainPath);
ds = new DirectorySearcher(de);
ds.PropertiesToLoad.Add("SAMAccountName");
ds.PropertiesToLoad.Add("member");
ds.Filter = "(&(objectClass=group)(SAMAccountName=" + groupName + "))";
SearchResult sr = ds.FindOne();
if (sr != null)
{
// do whatever you need to do with the entry
}
.... return list of users that belong to the specific GroupName ....
当我在 if 语句处设置断点时... sr 被列为 null...我不明白为什么它为 null...即使所选组中显然有成员...
我觉得,我不太明白如何在 ldap 查询中使用特定的组名......谁能指出我正确的方向?
【问题讨论】:
-
我认为 sr 可能为空,因为您在 SAMAccountName 上进行搜索,但您提供的是组名而不是帐户名。 SAMAccountName 应该是用于登录 AD 的名称。因此 ds.filter 行只会返回 1 个项目(假设某人的帐户名与组名相同)
标签: .net winforms active-directory ldap