我有一个MVC应用程序需要登录并验证用户对Active Directory.我使用PrincipalContext.ValidateCredentials方法,但总是得到一个验证为false.
连接到服务器是正常的.问题似乎发生在ValidateCredentials中.
这是我的代码:
public static bool IsAuthenticated(string domain,string username,string pwd) { bool IsAuthenticated = false; try { PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Domain,domain,"DC=c1w,DC=com"); username = "c1w\\" + username; IsAuthenticated = insPrincipalContext.ValidateCredentials(username,pwd); } catch (Exception ex) { // Rethrow this exception ExceptionPolicy.HandleException(ex,"Exception Policy"); } return IsAuthenticated; }
任何人都知道为什么会发生这种情况?