简体   繁体   English

c#GroupPrincipal.GetMembers性能问题

[英]c# GroupPrincipal.GetMembers Performance Problems

in our enviroment there are two AD Domains: DomainA and DomainB. 在我们的环境中有两个AD域:DomainA和DomainB。 There is a one way trust from DomainB to DomainA. 从DomainB到DomainA有单向信任。

We are using the following code to list all Users of an AD Group from DomainA from a Server in Domain (we are using a User from DomainA for the Principal Context): 我们使用以下代码从域中的服务器列出来自DomainA的AD组的所有用户(我们使用DomainA中的用户作为主体上下文):

using(PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "DomainA", "DomainA\\user", "pwd");
{
    using (GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, "DomainA\\DomainGroup"))
    { 
        var members = grp.GetMembers(true);

        foreach (Principal p in members)
        {
            string email = string.Empty;
            UserPrincipal u = p as UserPrincipal;

            if (u != null)
            {
                email = u.EmailAddress;
            }

            if (!String.IsNullOrEmpty(email) && !users.Contains(email))
            {
                users.Add(email);
            }
        }
    }
}

This code is executed within an IIS Webservice. 此代码在IIS Webservice中执行。

The code works quite well after a restart of the server in DomainB, but after a couple of tries the code gets extrem slow. 在DomainB中重新启动服务器后,代码运行良好,但经过几次尝试后,代码变得非常慢。 There are about 700 Members in the AD Group. AD集团约有700名成员。 The code takes about 5-10 seconds after the restart, after some time the code takes about 2-3 Minutes! 重启后大约5-10秒,代码大约需要2-3分钟!

Can anyone help me with this issue? 任何人都可以帮我解决这个问题吗?

Best Regards Bernhard 最好的问候伯恩哈德

Try with 试试吧

using (var members = grp.GetMembers(true))
{   }

The GetMembers call returns an IDisposable , and you're not it cleaning up. GetMembers调用返回一个IDisposable ,你不是在清理它。

See MS documentation here . 请参阅此处的 MS文档。

public class PrincipalSearchResult : IEnumerable, IEnumerable, IDisposable public class PrincipalSearchResult:IEnumerable,IEnumerable,IDisposable

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# - GroupPrincipal.GetMembers(true) - 哪个组? - C# - GroupPrincipal.GetMembers(true) - which group? C#-GroupPrincipal.Getmembers(true)不返回域用户,对此有什么选择? - C# - GroupPrincipal.Getmembers(true) not returning domain users, what is the alternative for this? GroupPrincipal.GetMembers和跨域成员错误 - GroupPrincipal.GetMembers and cross-domain members error Active Directory:DirectoryEntry成员列表&lt;&gt; GroupPrincipal.GetMembers() - Active Directory: DirectoryEntry member list <> GroupPrincipal.GetMembers() GroupPrincipal.GetMembers在组(或子组,如果递归)包含ForeignSecurityPrincipal时失败 - GroupPrincipal.GetMembers fails when group (or child group if recursive) contains ForeignSecurityPrincipal c# GroupPrincipal.FindByIdentity 找到组,但在使用 GetMembers 时出现错误 - 服务器上没有这样的 object - c# GroupPrincipal.FindByIdentity finds the group, but when using GetMembers getting error - there is no such object on the server 无法成功通过AccountManagement.GroupPrincipal GetMembers对象进行迭代 - Cannot successfully iterate through AccountManagement.GroupPrincipal GetMembers Object C#Performance MS verse Mono Problems - C# Performance MS verse Mono Problems 如何在 C# .NET 4.5 中使用 GroupPrincipal 创建 AD 组? - How do I create an AD group using GroupPrincipal in C# .NET 4.5? 通过C#使用MongoDB聚合框架时的性能问题 - Performance problems when using MongoDB Aggregation Framework through C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM