该代码在我的本地计算机上运行良好,但是当发布到服务器时,它将在目录上抛出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();

最佳答案

可能的原因:


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

07-26 07:38