我有一個使用Ldap查詢的組名列表...我已經將列表名稱綁定到WinForms應用程序中的數據網格。當用戶選擇的組名稱中的一個,一個事件被觸發,組名被傳遞到下面的方法: -.NET Active Directory - 獲取特定Active Directory組中的用戶列表
// 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 ...我不理解爲什麼它的空...即使選定的組明確地有其成員...
我覺得,我不太明白如何使用特定的組名稱ldap查詢...任何人都可以指向正確的方向嗎?
我覺得SR,因爲你是在SAM帳戶名搜索可能是空的但代替您提供組名稱的帳戶名稱。 SAMAccountName應該是用於登錄到AD的名稱。因此,ds.filter行只會返回1個項目(假設某人的帳戶名稱與組名相同) –