下面code正常工作,从各种对我们的域的机器。
The following code works fine from a variety of machines on our domain.
var context = new PrincipalContext(ContextType.Domain); var principal = UserPrincipal.FindByIdentity(context, @"domain\username")
但是,如果我运行一个机器,是不是在域在此类似code,它的工作原理,但FindByIdentity线采用2 +秒。
However, if I run this similar code on a machine that is not on a domain, it works but the FindByIdentity line takes 2+ seconds.
var context = new PrincipalContext(ContextType.Machine); var principal = UserPrincipal.FindByIdentity(context, @"machinename\username")
可以这样性能上的差异通过提供特殊参数的PrincipalContext构造和/或FindByIdentity方法来解决?是否有可能被调整在IIS或Windows设置?
最起码,有谁能够告诉我,为什么它可能是在第二个方案中慢?
在code是从ASP.NET MVC 3应用程序在Windows Server 2008上的IIS中承载7.5(综合管线)运行R2。
The code is running from an ASP.NET MVC 3 app hosted in IIS 7.5 (Integrated Pipeline) on Windows Server 2008 R2.
推荐答案我有同样的问题。试试下面的块code。我不知道为什么,但它的速度更快(忽略第一次登录缓慢建立后VS - 后续登录都被迅速)。看到类似SO质疑Why将使用PrincipalSearcher比FindByIdentity快()?
I had the same problem. Try the below block of code. I don't know why but it's much faster (ignore first time slow login after build in VS - subsequent logins are speedy). See similar SO question Why would using PrincipalSearcher be faster than FindByIdentity()?
var context = new PrincipalContext( ContextType.Machine ); var user = new UserPrincipal(context); user.SamAccountName = username; var searcher = new PrincipalSearcher(user); user = searcher.FindOne() as UserPrincipal;
根本的问题可能有事情做与NetBIOS调用。请参阅ADLDS很慢(往返为\服务器* \ MAILSLOT \ NET \ NETLOGON)
更多推荐
FindByIdentity
发布评论