[英]Connect to ActiveDirectory in C# fails
我嘗試在C#中連接到AD
如果我連接到根,它將成功而不會引發錯誤。
try {
DirectoryEntry de = new DirectoryEntry("LDAP://COMPANYDOMAIN.COM", "username", "password");
object nativeObject = de.NativeObject;
} catch(DirectoryServicesCOMException) { }
如果我使用如下所示的另一種方式連接,它將引發the specified domain either does not exist or could not be contacted.
try {
DirectoryEntry de = new DirectoryEntry("LDAP://DC=COMPANYDOMAIN,DC=COM", "username", "password");
object nativeObject = de.NativeObject;
} catch(DirectoryServicesCOMException) { }
如果我連接到子OU,它將引發the specified domain either does not exist or could not be contacted.
太
try {
DirectoryEntry de = new DirectoryEntry("LDAP://OU=KEE2, DC=COMPANYDOMAIN,DC=COM", "username", "password");
object nativeObject = de.NativeObject;
} catch(DirectoryServicesCOMException) { }
我可以使用LDAPADMIN
GUI工具進行連接並查看AD中的結構:
ROOT
OU=KEE2
OU=KEE
OU=other..
我在這里做錯了什么?
事實證明,所使用的語法是錯誤的……必須像這樣……然后沒有錯誤。
LDAP://companydomain.com/ou=kee2,dc=COMPANYDOMAIN,dc=com
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.