【发布时间】:2018-03-12 19:22:35
【问题描述】:
我正在尝试编写一些代码来使用 c# 将对象写入 Active Directory。我有一个测试域控制器,它不是我编写代码的笔记本电脑所属的域或林的成员。我已经尝试了以下所有组合中的用户名和服务器替换,但是当我到达该行时
adobject = myLdapConnection.Children.Add(value, type);
我找回了错误
用户名或密码不正确。
如果用户名和密码正确,为什么会出现此错误?
testuser 是域管理员。我可以使用像 Softerra LDAP Browser 这样的程序来验证它是否正确,该程序可以很好地连接到服务器并让我创建对象。
//string username = "CN=testuser,CN=Users,DC=ad,DC=domain,DC=com";
//string username = "testuser";
//string username = "AD\\testuser";
//string server="LDAP://10.10.10.10:389";
//string server="LDAP://10.10.10.10";
string server = "LDAP://10.10.10.10:389";
string basedn = "ou=testou,DC=ad,DC=domain,DC=com";
string username = "CN=testuser,CN=Users,DC=ad,DC=domain,DC=com";
string password="plaintextpassword";
DirectoryEntry myLdapConnection = new DirectoryEntry(server+"/"+basedn,username,password,AuthenticationTypes.Secure);
string value="ou=testsubou,ou=testou,DC=ad,DC=domain,DC=com";
string type="organizationalUnit";
DirectoryEntry adobject = myLdapConnection.Children.Add(
value, type);
adobject.CommitChanges();
【问题讨论】:
-
在你的代码中
myLdapConnection应该是ldapConnection吗? -
更改了代码以反映。输入示例时我的错字。
标签: c# active-directory ldap directoryentry