DirectoryEntry entry = new DirectoryEntry(ADPath, userName, password, AuthenticationTypes.None);
 return entry;
 
用以上代码构造出一个entry对象,再利用entry构造出一个DirectorySearcher,利用其搜索出一个DirectoryEntry,但在访问DirectoryEntry对象的Properties属性时,报
异常详细信息: System.DirectoryServices.DirectoryServicesCOMException: 登录失败: 未知的用户名或错误密码。 DirectoryEntry de = GetDirectoryEntryByAccount(sAMAccountName);
 if (de != null)
 {
   string commonName = de.Properties["cn"][0].ToString();//主要出错是这段代码〈〈〈〈〈〈=====
 } 以上的ADPath, userName, password 均在LDP.EXE中使用没有问题,但是代码实现中就有问题,不知是哪方面的问题。请指教!!!

解决方案 »

  1.   

    AuthenticationTypes.ServerBind试一下。
      

  2.   

        ///
        ///获得DirectoryEntry对象实例,以管理员登陆AD
        ///
        ///
     private static DirectoryEntry GetDirectoryObject()
     {
        DirectoryEntry entry = new DirectoryEntry(ADPath, ADUser, ADPassword, AuthenticationTypes.ServerBind);
        return entry;
     }
    其实这个方法先前就有试过,刚才再重新试了下,依然出现以下错误."登录失败: 未知的用户名或错误密码"
      

  3.   


    ADPath = "LDAP://这种";
    ADUser = "domain/userName";
      

  4.   


    正如 bluebrother 兄所说
    ADPath = "LDAP://这种";
    ADUser = "domain/userName";
    使用的是这个,而且在LDP.EXE中是可以登陆的....
      

  5.   

       一样的问题,是不是对于每次用DirectoryEntry对象都要用用户名和密码去构造,这块不知道怎么搞的!!