0
我一直在寻找一种方法来确定是否一个目录的用户的帐户已禁用或没有,但使用PrincipalContext
方法:确定是否一个目录的用户的帐户已禁用帐户使用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
我很惊讶,我错过了这一个。我会测试一下。 – DoomerDGR8 2014-09-21 08:50:37