c# - 从事件目录中检索组下的用户列表时出错(C# 中的 System.DirectoryServices.AccountManagement)

标签 c# .net authentication active-directory

我在从事件目录中检索组下的用户时遇到错误。错误描述是 {“无法检索有关域的信息 (1355)”}。尝试使用 .Net 4.0 和 .Net 4.5。 我收到错误的行已用错误消息进行注释。

public List<DirectoryUser> GetUsersUnderGroup(string groupName)
    {
        var directoryUserList = new List<DirectoryUser>();
        string directoryServerIp="192.168.1.xxx";
        string ouName="xxxOuName";
        string domainComponents="DC=xxxComopnent1,DC=xxxComponent2";
        string directoryAdminUserId="directoryAdminuser";
        string directoryAdminPassword="directoryAdminPassword";
        using (var principalContext = principalContext = new PrincipalContext(ContextType.Domain, directoryServerIp, string.Format("OU={0},{1}", ouName, domainComponents), directoryAdminUserId, directoryAdminPassword);)
        {
            using (var group = GroupPrincipal.FindByIdentity(principalContext, groupName))
            {
                if (group != null)
                {                       
                    var users = group.GetMembers(true);
                    //Works fine till the above line. variable users is having not null value but
                    //exception while iterating through the loop.Following is the exception
                    //{"Information about the domain could not be retrieved (1355)."}
                    foreach(var user in users)
                    {                            
                        Console.Write(user.DistinguishedName);
                    }
                }
            }
        }
        return directoryUserList;
    }

创建 PrincipalContext 的代码在其他情况下工作正常(例如获取组列表和 OU 等)

最佳答案

本文介绍了您遇到问题的原因和可能的解决方案:link .基本上,如果您不是从域 Controller 所在的计算机运行代码,则必须使用 DirectoryEntry 类。 本文应该可以帮助您理解该类:link

关于c# - 从事件目录中检索组下的用户列表时出错(C# 中的 System.DirectoryServices.AccountManagement),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27291565/

相关文章:

c# - 如何获得不同的列表?

c# - WPF AvalonEdit SQL xhsd 请求

c# - 如何将文件/目录上传到存储桶中的文件夹?

c# - Release Build 包含额外的文件,我需要这些吗?

php - Zend2 + Doctrine2 认证

Django 使用管理站点添加远程用户

c# - Interlocked.CompareExchange 在 dapper .net 方法中用于什么?

c# - 无法将发布值从 ajax 传递到 .net c# 中的页面

c# - 安装Windows服务时是否需要手动创建Windows事件日志源

javascript - 在Backbone js中永久引用另一条数据