c# - 使用 PrincipalContext.ValidateUser 时的性能问题

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

我正在使用讨论的解决方案 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);
    }
}

我尝试添加 namecontainer 参数,如 msdn 中所述到 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)

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

最佳答案

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

关于c# - 使用 PrincipalContext.ValidateUser 时的性能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4469795/

相关文章:

C#——如果一个对象在以下范围内没有用,我应该将它设为 NULL 吗?

c# - Windows 窗体中的多级组合框

Azure AD B2C 在用户中导入

c# - ASP.Net 成员(member)资格 : Roles saved on Different Database

c# - 登录控制和自定义成员(member)提供者

model-view-controller - 如何在自定义MembershipProvider上调用Initialize?

c# - 如何在 Mono 开发(Ubuntu、Linux)中将 Saltarelle C# 设置为 JavaScript 编译器

c# - ASP.Net Core 2.1 IdentityCore(用户登录时未添加角色声明)

active-directory - 在 Active Directory 中创建用户时出现 C# 错误

用于组织、团队和用户管理的 Azure AD B2C 或 B2B