c# LDAP 连接到林外域

c# LDAP connection to domain outside forest

我正在尝试编写一些代码以使用 c# 将对象写入 Active Directory。我有一个测试域控制器,它不是我编写代码的笔记本电脑所属的域或林的成员。我已经尝试在所有组合中对用户名和服务器进行以下替换,但是当我到达行时

adobject = myLdapConnection.Children.Add(value, type);

我找回错误

用户名或密码不正确。

如果用户名和密码正确,为什么我会收到此错误消息?

testuser 是域管理员。我可以使用像 Softerra LDAP 浏览器这样的程序来验证它是否正确,它可以很好地连接到服务器并让我创建对象。

//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();

用户名应采用 "normal" 格式,而不是 "CN=testuser,CN=Users,DC=ad,DC=domain,DC=com";。正常表示 DOMAIN\USERuser@DOMAIN.XXX