Emi*_*l G 5 c# asp.net-membership active-directory
我正在使用此处讨论的解决方案根据我的 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);
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试将msdn上记录的名称和容器参数添加到 PrincipalContext 构造函数,但这些参数似乎没有任何影响。
using (var context = new PrincipalContext(ContextType.Domain, "MyDomain", "OU=MyCompany,DC=some,DC=stuff")) {
return context.ValidateCredentials(username, password);
}
Run Code Online (Sandbox Code Playgroud)
我们的网络中至少有两台不同的服务器存在同样的问题。服务器连接到 AD 并运行操作系统 Windows server 2003 SP2 (IIS6)
我的一个想法是,这个问题可能与我们的域对其他域有一些信任的事实有关,并且在验证用户时它们以某种方式参与。但是,我们尝试验证的用户仅存在于“我们的”广告中。
遇到这个问题,必须使用ValidateCredentials(string, string, ContextOptions)方法传递正确的枚举组合来访问我们环境中的 ActiveDirectory 连接。