May*_*ayo 16 .net iis-7 directoryservices
以下代码可以在我们域上的各种计算机上正常运行.
var context = new PrincipalContext(ContextType.Domain);
var principal = UserPrincipal.FindByIdentity(context, @"domain\username")
Run Code Online (Sandbox Code Playgroud)
但是,如果我在不在域上的计算机上运行此类似的代码,它可以工作,但FindByIdentity行需要2秒以上.
var context = new PrincipalContext(ContextType.Machine);
var principal = UserPrincipal.FindByIdentity(context, @"machinename\username")
Run Code Online (Sandbox Code Playgroud)
通过向PrincipalContext构造函数和/或FindByIdentity方法提供特殊参数,可以解决这种性能差异吗?IIS或Windows中是否有可以调整的设置?
至少,任何人都可以告诉我为什么在第二种情况下它可能会变慢?
该代码从Windows Server 2008 R2上的IIS 7.5(集成管道)中托管的ASP.NET MVC 3应用程序运行.
Jim*_*TAT 23
我有同样的问题.试试下面的代码块.我不知道为什么但速度要快得多(在VS中构建后忽略第一次缓慢登录 - 后续登录速度很快).看到类似的SO问题为什么使用PrincipalSearcher比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;
Run Code Online (Sandbox Code Playgroud)
潜在的问题可能与netBios调用有关.请参阅ADLDS非常慢(往返于\ Server*\MAILSLOT\NET\NETLOGON)
| 归档时间: |
|
| 查看次数: |
5161 次 |
| 最近记录: |