我正在嘗試使用C#連接到AD服務器。這是我第一次玩AD.Domain,我需要連接到abc.def.com。使用憑證連接到Active Directory
這是一個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();
如果您沒有指定AuthenticationType? – tdelepine
@tdelepine:如果未指定AuthenticationType,則會出現相同的錯誤。 –