我正在尝试使用 C# 连接到 AD 服务器。这是我第一次玩 AD.Domain 我需要连接的是 abc.def.com。
这是一个 ASP.NET 网站,它给出了这个错误。但是我可以使用相同的凭据使用“ldp.exe”登录到同一个域。有人知道吗?
[DirectoryServicesCOMException (0x8007052e): Logon failure: unknown user name or bad "password.
]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +387825
System.DirectoryServices.DirectoryEntry.Bind() +36
System.DirectoryServices.DirectoryEntry.get_AdsObject() +31
这是我的代码
static System.DirectoryServices.DirectoryEntry createDirectoryEntry()
{
System.DirectoryServices.DirectoryEntry ldapConnection = new System.DirectoryServices.DirectoryEntry("13.18.12.16", "Administrator", "admin123");
ldapConnection.Path = "LDAP://ou=Users,dc=abc,dc=def,dc=com";
ldapConnection.AuthenticationType = System.DirectoryServices.AuthenticationTypes.Secure;
return ldapConnection;
}
System.DirectoryServices.DirectoryEntry sgscAd = createDirectoryEntry();
System.DirectoryServices.DirectorySearcher search = new System.DirectoryServices.DirectorySearcher(sgscAd);
search.Filter = "(cn=" + m_username + ")";
System.DirectoryServices.SearchResult result = search.FindOne();