【问题标题】:Performance problems when using PrincipalContext.ValidateUser使用 PrincipalContext.ValidateUser 时的性能问题
【发布时间】:2011-05-27 01:39:22
【问题描述】:

我正在使用here 讨论的解决方案针对我的 ASP.NET Web 应用程序中的活动目录对用户进行身份验证。我编写了一个简单的 ADMembershipProvider 类,它与 FormsAuthentication 一起使用。在本地运行项目时工作正常,但当部署到网络中的服务器时,ValidateUser 调用需要很长时间(大约 20 秒)。

//Assumes using System.DirectoryServices.AccountManagement
public override bool ValidateUser(string username, string password) {
    using (var context = new PrincipalContext(ContextType.Domain)) {
        return context.ValidateCredentials(username, password);
    }
}

我尝试将 msdn 中记录的 namecontainer 参数添加到 PrincipalContext 构造函数,但这些参数似乎没有任何效果。

using (var context = new PrincipalContext(ContextType.Domain, "MyDomain", "OU=MyCompany,DC=some,DC=stuff")) {
    return context.ValidateCredentials(username, password);
}

我们网络中至少有两台不同的服务器存在同样的问题。服务器连接到 AD 并运行 OS Windows server 2003 SP2 (IIS6)

我的一个想法是,问题可能与我们的域对其他域有一些信任这一事实有关,并且在验证用户时它们以某种方式参与。但是,我们尝试验证的用户仅存在于“我们的”广告中。

【问题讨论】:

  • 您是在 IISUser 或网络服务下运行的站点/应用程序池吗?后者可能更快,但不建议在该帐户下运行网站。
  • 好的,谢谢,该站点已经作为网络服务运行了
  • 我猜这是因为您将 NetBIOS 名称传递给您的 PrincipalContext()。尝试传入 DNS 域名。

标签: c# active-directory asp.net-membership


【解决方案1】:

遇到这个问题,必须使用ValidateCredentials(string, string, ContextOptions) 方法传入正确的枚举组合,才能在我们的环境中访问我们的 ActiveDirectory 连接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-06
    • 2010-10-04
    • 2012-07-01
    • 2021-07-02
    • 1970-01-01
    相关资源
    最近更新 更多