我的AD服务目录配置好下:
域名:ASC.CORP.INT-PAS域名下的目录结构为:
Users ---> Department ----> People ---> BJ我在C#里写的连接字符串为:LDAP://172.30.176.11:389/dc=ASC,dc=CORP,dc=INT-PAS,ou=Users,ou=Department,ou=People,ou=BJ
用户名和密码是登录域的用户名和密码DirectoryEntry de = new DirectoryEntry("LDAP://172.30.176.11:389/dc=ASC,dc=CORP,dc=INT-PAS,ou=Users,ou=Department,ou=People,ou=BJ","abc", "password", AuthenticationTypes.Secure);当我做Search的时候得到的错误是:"该服务器不可操作",请问我的连接字符串是否正确(如果不正确应该怎么写),用户名和密码是登陆域的用户名和密码吗,还是登录域所在机器的用户和密码?还有“该服务器不可操作”是什么意思,怎样解决?谢谢。

解决方案 »

  1.   


    查找指定的用户,显示其所有属性
    public void SearchUser(string userName)
            {
                DirectoryEntry deUser = new DirectoryEntry("LDAP://10.99.185.18/DC=zhaijx,DC=cn","codingtaoist","54638");
                DirectorySearcher   src   =   new   DirectorySearcher(deUser); 
                src.Filter   =   "(&(objectClass=user)(SAMAccountName="+userName+"))";
                
                src.SearchRoot   =   deUser; 
                src.SearchScope   =   SearchScope.Subtree;
                SearchResult   result   =   src.FindOne(); 
                DirectoryEntry   objDirEnt   =   new   DirectoryEntry(result.Path,  "codingtaoist","54638",   AuthenticationTypes.Secure); 
                IDictionaryEnumerator e = objDirEnt.Properties.GetEnumerator();
                Response.Write("<table>");
                while(e.MoveNext())
                {
                    DisplayOneProperty(objDirEnt,e.Key.ToString());
                }
                Response.Write("</table>");
                
            }    public void DisplayOneProperty(DirectoryEntry de ,  string   PropertyName) 
            { 
                if   (de.Properties.Contains(PropertyName)) 
                { 
                    string myvalue=  de.Properties[PropertyName].Value.ToString(); 
                    Response.Write("<tr>");
                    Response.Write("<td>");
                    Response.Write(PropertyName);
                    Response.Write("</td>");
                    Response.Write("<td>");
                    Response.Write(myvalue);
                    Response.Write("</td>");
                    Response.Write("</tr>");
                    
                } 
            } 
     判断用户是否禁用private bool isDisable(DirectoryEntry de)
            {
                if(de.Properties.Contains("UserAccountControl")) 
                { 
                    string myvalue=  de.Properties["UserAccountControl"].Value.ToString(); 
                    if(myvalue=="514")
                    {
                        return true;
                    };
                } 
                return false;
            }
      

  2.   

    DirectoryEntry de = new DirectoryEntry("LDAP://172.30.176.11:389/dc=ASC,dc=CORP,dc=INT-PAS,ou=Users,ou=Department,ou=People,ou=BJ","abc", "password", AuthenticationTypes.Secure); 当我做Search的时候得到的错误是:"该服务器不可操作", 请问我的连接字符串是否正确(如果不正确应该怎么写),
    =======
    错误了! 路径要反过写!
    ou=BJ,ou=People, ... dc=ASC,dc=CORP,dc=INT-PAS
    用户名和密码是登陆域的用户名和密码吗,还是登录域所在机器的用户和密码?=======域账号!!! 如果没有权限,会报 拒绝访问之类
    还有“该服务器不可操作”是什么意思,怎样解决?谢谢。=======这个错误比较泛(AD COM 报错通常比较弱智),你这里可能是指定的 LDAP 地址无法达到,可能 IP 或者 端口错误,或者 路径错误
      

  3.   

    多谢各位,问题终于解决了。
    to  Jinglecat 你的回答"路径要反过写!",真是正解。太谢谢你了。to zzxap 参考了一下你的原代码,很有用,谢谢。