在我们的环境中有两个AD域: DomainA和DomainB。从DomainB到DomainA有一种单向信任。
我们使用以下代码从域中的服务器中从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);
}
}
}
}此代码在IIS Webservice中执行。
在DomainB中重新启动服务器之后,代码运行得很好,但是经过几次尝试,代码变得非常慢。广告集团约有700名成员。代码在重启后大约需要5-10秒,经过一段时间后,代码大约需要2-3分钟!
有人能帮我解决这个问题吗?
向伯恩哈德问好
发布于 2018-06-07 13:20:28
试着
using (var members = grp.GetMembers(true))
{ }GetMembers调用返回一个IDisposable,而不是清理。
参见MS文档这里。
公共类PrincipalSearchResult : IEnumerable,IEnumerable,IDisposable
https://stackoverflow.com/questions/50742267
复制相似问题