我已经设置了一个 ADAM 实例并添加了一些测试用户。在 c# 中,我可以使用 Windows 帐户绑定到 ADAM,但无法使用 ADAM 用户之一进行绑定。(我可以在 ldp 中成功绑定 adam 用户)并且我已通过将 msDS-UserAccountDisabled 属性设置为 false 来确保启用了用户。当我与我的 Windows 帐户绑定时,我可以成功搜索并带回 ADAM 用户的属性,但我仍在努力对他们进行身份验证,当我尝试与 ADAM 用户帐户绑定时,我收到错误:
错误:System.Runtime.InteropServices.COMException (0x8007052E):登录失败:未知用户名或密码错误。在 System.DirectoryServices.DirectoryEntry.Bind(布尔 throwIfFail)
这是我正在使用的代码:
string userName = txtUserName.Text;
string password = txtPassword.Text;
string ADConnectionString = "LDAP://localhost:389/CN=sandbox,DC=ITOrg";
DirectoryEntry entry = new DirectoryEntry(ADConnectionString);
entry.Username = "myComputer\\Administrator";
entry.Password = "myPassword";
try
{
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(&(objectClass=user)(CN=" + userName + "))";
SearchResultCollection result = searcher.FindAll();
if (result.Count > 0)
{
//bind with simple bind
using (DirectoryEntry de = new DirectoryEntry(result[0].Path, userName, password,AuthenticationTypes.None))
{
if (de.Guid != null) // this is the line where it dies
{
Label1.Text = "Successfully authenticated";
Label2.Text = result[0].Properties["displayName"][0].ToString();
Label3.Text = result[0].Properties["telephoneNumber"][0].ToString();
} else
{
Lable1.Text = "Unable to Authenticate";
}
}
}
else
{
Lable1.Text = "UserName :" + userName + " not found";
}
} catch(Exception ex)
{
Label1.Text = "Error searching: " + ex.ToString();
}
在此先感谢您的帮助,非常感谢!