[英]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.