我一直在寻找一种方法来确定目录用户的帐户是否被禁用,但使用PrincipalContext
方法:
using (var validatePrincipalContext = GetPrincipalContext())
{
using (var retrievedUserPrincipal = UserPrincipal.FindByIdentity(validatePrincipalContext, directoryUserName))
{
if (retrievedUserPrincipal == null)
{
LogMessage(String.Format("User {0} failed to verify on {1}.", directoryUserName, domainNameV), Severity.Error);
throw new PlatformException(ErrorCode.DomainCredentialsFailed, new Dictionary<string, string>
{
{"ADUserName", directoryUserName},
{"DirectoryIdentifier", domainNameV}
});
}
// Actual validation
if (validatePrincipalContext.ValidateCredentials(directoryUserName, directoryUserPassword))
{
LogMessage(String.Format("User {0} verified successfully on {1}.", directoryUserName, domainNameV), Severity.Info);
return retrievedUserPrincipal.UserPrincipalName;
}
LogMessage(String.Format("User {0} failed to verify on {1}.", directoryUserName, domainNameV), Severity.Info);
return String.Empty;
}
}
我在这里搜索并看到一些人使用第二种方法与目录:DirectoryEntry和DirectorySearcher方法(How to determine if user account is enabled or disabled)。我无法使用它,因为我已经使用PrincipalContext
答案 0 :(得分:0)
您可以检查UserPrincipal
上有多个属性和方法:
Enabled
:用户的帐户是否已启用IsAccountLockedOut()
:返回一个布尔值,指定帐户当前是否已被锁定。