C# 正在确定用户密码何时过期Active Directory,引发错误的异常
当用户密码设置为在AD中下次登录时更改时,用户无法登录,因为他们的密码显示不正确。我希望能够在身份验证时确定这一点,并提示用户更改密码 我明白要做到这一点,我需要捕获本节中描述的DirectoryServicesCOMException,但是不会引发异常,而引发的异常是一个Interop.COMException,它位于继承的更高层 这不包含确定密码是否需要更改或不正确所需的信息C# 正在确定用户密码何时过期Active Directory,引发错误的异常,c#,authentication,exception-handling,active-directory,dotnetnuke,C#,Authentication,Exception Handling,Active Directory,Dotnetnuke,当用户密码设置为在AD中下次登录时更改时,用户无法登录,因为他们的密码显示不正确。我希望能够在身份验证时确定这一点,并提示用户更改密码 我明白要做到这一点,我需要捕获本节中描述的DirectoryServicesCOMException,但是不会引发异常,而引发的异常是一个Interop.COMException,它位于继承的更高层 这不包含确定密码是否需要更改或不正确所需的信息 private bool IsAuthenticated(string Path, string UserName,
private bool IsAuthenticated(string Path, string UserName, string Password)
{
try
{
DirectoryEntry userEntry = new DirectoryEntry(Path, UserName, Password); //, AuthenticationTypes.Signing)
var obj = userEntry.NativeObject;
return true;
}
catch (DirectoryServicesCOMException ex)
{
if (ex.ExtendedErrorMessage.Contains(" 773,") || ex.ExtendedErrorMessage.Contains("532"))
{
EventLogController.Instance.AddLog("Password expired", ex.ExtendedErrorMessage, Globals.GetPortalSettings(), -1, DotNetNuke.Services.Log.EventLog.EventLogController.EventLogType.ADMIN_ALERT);
System.Web.HttpContext.Current.Response.Cookies["sync_expiryToken"].Value = "1";
return true;
}
return false;
}
catch (COMException ex)
{
EventLogController.Instance.AddLog("Password wrong", ex.ToString(), Globals.GetPortalSettings(), -1, DotNetNuke.Services.Log.EventLog.EventLogController.EventLogType.ADMIN_ALERT);
return false;
}
catch (Exception ex)
{
Exceptions.LogException(ex);
return false;
}
}
我终于找到了答案 某些身份验证类型仅抛出COMException而不是DirectoryServicesCOMException 将身份验证类型设置为AuthenticationTypes。ldap上的None解决了此问题