【问题标题】:c# LDAP connection to domain outside forestc# LDAP 连接到林外域
【发布时间】: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


【解决方案1】:

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

【讨论】:

  • 我也是这么想的,但是微软的人说的不一样:social.technet.microsoft.com/Forums/windows/en-US/…
  • 无论如何,它可能值得一试。
  • @GabrielLuci 我从未使用 DN 作为登录名。如果它有效,我会学到一些新东西:D
  • DN 和普通的 DOMAIN\USER 似乎都不起作用,但 user@DOMAIN.XXX 可以。
  • 请注意,如果我想在创建 OU 时使用完整的 dn,我还必须放弃 basedn。
猜你喜欢
  • 2018-01-10
  • 2010-11-29
  • 1970-01-01
  • 1970-01-01
  • 2016-01-09
  • 2014-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多