여기에 미쳐 가고 있습니다. 정말 도움이되었습니다. 단순히 DirectoryEntry 클래스를 사용하여 Active Directory에서 사용자 이름 또는 기타 항목을 가져 오려고합니다.Directoryentry에서 사용자를 가져올 수 없습니다.
userprinciple을 사용했는데 훌륭하게 작동하지만, (사용자의 관리자)에게 필요한 속성은 DirectoryEntry에서만 사용할 수 있습니다.
내 문제는 내가 온라인에서 너무 많이 보였고 거기에서 코드를 얻었지만 어떤 이유로 결코 작동하지 않으며 항상 Null을 반환합니다. 여기 예가 있습니다 :
public static DirectoryEntry GetUser(string UserName)
{
//create an instance of the DirectoryEntry
DirectoryEntry de = new DirectoryEntry("LDAP://" + "OU=AnotherOU,OU=xx,OU=Testvironments,DC=abc,DC=local");
//create instance fo the direcory searcher
DirectorySearcher deSearch = new DirectorySearcher(de);
deSearch.SearchRoot = de;
//set the search filter
deSearch.Filter = "(&(objectCategory=user)(cn=" + UserName + "))";
//deSearch.SearchScope = SearchScope.Subtree;
//find the first instance
SearchResult results = deSearch.FindOne();
//if found then return, otherwise return Null
if (results != null)
{
//de= new DirectoryEntry(results.Path,ADAdminUser,ADAdminPassword,AuthenticationTypes.Secure);
//if so then return the DirectoryEntry object
return results.GetDirectoryEntry();
}
else
{
return null;
}
}
이 코드가 null을 반환하는 이유는 없습니다.
미리 감사드립니다.
여기에 도메인 이름은 사용자가 기기에 로그인하려는 사용자 ID입니다. 고유 ID입니다. 죄송합니다. 여기에 다른 것을 사용 했어야합니다 ... – RL89