生产环境中出现 DirectoryServicesComException,但本地计算机上没有 C# ASP.net

发布于 2024-12-20 13:11:52 字数 1130 浏览 2 评论 0原文

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

results = mySearcher.FindAll();

代码行上抛出 DirectoryServiceCOMException 。 我的函数传递两个搜索框的内容,用户可以在其中按姓名或职位查找员工:

        // 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();

The code works great on my local machine but when published to the server it throws the DirectoryServiceCOMException on the

results = mySearcher.FindAll();

line of the code.
My function passes the contents of two searchboxes where the user can lookup an employee by name or position:

        // 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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍景流年 2024-12-27 13:11:52

可能原因:

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

Possible reasons:

  1. the app pool identity on the server is not authorized to connect to the AD. check the app pool identity, set it to the domain admin account for validation
  2. the server is not connected to AD
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文