如何仅仅过一步验证Active Directory中的凭据并实际登录用户?以便上次登录时间在命令'net user username / domain'中更改...我认为ValidateCredentials方法中的ContextOptions.Negotiate将实现此目的,但事实并非如此。我究竟做错了什么?这是我的Authenticate方法。
public static bool Authenticate(ServiceInfo adConfig, string username, string password) {
using (var principalContext = new PrincipalContext(ContextType.Domain, adConfig.Domain, adConfig.Container, adConfig.Username, adConfig.Password)) {
if (principalContext.ValidateCredentials(username, password, ContextOptions.Negotiate)) {
using (var userPrincipal = UserPrincipal.FindByIdentity(principalContext, IdentityType.SamAccountName, username)) {
if (userPrincipal != null) {
return true;
}
}
}
return false;
}
}