如何使用用户名和密码在LDAP中检索EmployeeID

问题描述:

您好,



我可以通过LDAP使用以下代码对用户进行身份验证。任何人都可以建议我如何撤销相应用户名的用户ID。我想知道如何查询LDAP以检索相应用户名的UserID。



Hello,

I am able to authenticate the users using the following code through LDAP. Can anyone please suggest me how to retieve the User Id for the corresponding Username. I wanted to kow how can we query LDAP to retrieve the UserID for the coresponding Username.

try
{
    LdapConnection connection = new LdapConnection("myserver.mycompany.com");
    NetworkCredential credential = new NetworkCredential(textBoxUsername.Text, passwordBox.Password);
    connection.Credential = credential;
    connection.Bind();
    AddData admin = new AddData();

    admin.Show();
    this.Close();
}
catch (LdapException lexc)
{
    String error = lexc.ServerErrorMessage;
    MessageBox.Show("User Authentication Failed! Please Try again.");
}
catch (Exception exc)
{
    MessageBox.Show(Convert.ToString(exc));
}

SELECT userid,来自TableName的用户名
SELECT userid, username from TableName