DirectoryServicesComException生产但不是本地机器C#ASP.net

时间:2011-12-09 15:13:26

标签: c# active-directory

代码在我的本地计算机上运行良好但是当发布到服务器时它会在

上抛出DirectoryServiceCOMException
results = mySearcher.FindAll();

代码行。 我的函数传递两个搜索框的内容,用户可以通过名称或位置查找员工:

        // Bind to the users container.
        string path = "LDAP://DC=DOMAIN,DC=TLD";
        DirectoryEntry entry = new DirectoryEntry(path);

        // Create a DirectorySearcher object.
        DirectorySearcher mySearcher = new DirectorySearcher(entry);

        // Set a filter for users with the name test.
        mySearcher.Filter = "(&(objectClass=user)";

        if (employeeName != "")
        {
            mySearcher.Filter = mySearcher.Filter + "(name=*" + employeeName + "*)";
        }
        if (position != "")
        {
            mySearcher.Filter = mySearcher.Filter + "(title=*" + position + "*)";
        }
        mySearcher.Filter = mySearcher.Filter + ")";
        mySearcher.Sort = new SortOption("sn", System.DirectoryServices.SortDirection.Ascending);


        // Use the FindAll method to return objects to a 
        // SearchResultCollection.
        results = mySearcher.FindAll();

1 个答案:

答案 0 :(得分:3)

可能的原因:

  1. 服务器上的应用程序池标识无权连接到AD。检查应用程序池标识,将其设置为域管理员帐户以进行验证
  2. 服务器未连接到AD