C# LDAP认证登录

http://blog.csdn.net/lnas_01/article/details/43987259

public class LDAPHelper  
{  
    string ldapUrl="LDAP://***.***.48.110:389/dc=***,dc=com";  
    string ldapUserName = "cn=root,dc=***,dc=com";  
    string ldapPassword = "pw";  
    public LDAPHelper(string ldap_url,string ldap_user,string ldap_pwd )  
    {  
        ldapUrl = ldap_url;  
        ldapUserName = ldap_user;  
        ldapPassword = ldap_pwd;  
    }  
  
    public bool login()  
    {  
        DirectoryEntry root = null;  
        try  
        {  
            root = new DirectoryEntry(ldapUrl, ldapUserName, ldapPassword, AuthenticationTypes.None);  
            string strName = root.Name;//失败,会抛出异常  
            root.Close();  
            root = null;  
            return true;  
        }  
        catch(Exception ex)  
        {  
            return false;  
        }  
    }  
}  

 

posted @ 2017-02-19 10:22  shiningrise  阅读(969)  评论(0编辑  收藏  举报