FindByIdentity - 性能差异 [英] FindByIdentity - performance differences

查看:291
本文介绍了FindByIdentity - 性能差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面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质疑<一href="http://stackoverflow.com/questions/11799457/why-would-using-principalsearcher-be-faster-than-findbyidentity">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调用。请参阅<一href="http://social.technet.microsoft.com/Forums/eu/winserverDS/thread/20eb50e9-3e68-4d29-bcdd-a4fc166b9c00">ADLDS很慢(往返为\服务器* \ MAILSLOT \ NET \ NETLOGON)

这篇关于FindByIdentity - 性能差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆