J L*_*erg 2 c# active-directory
首先,我知道有很多关于该主题的文章,但是我发现的所有信息对我的情况没有帮助。发生的事情是我找不到该属性用于将用户锁定在AD中。我用过
对于使用AD进行的其他所有操作,并且一切正常,如果帐户被锁定,则userAccountControl的位图不会更改。尝试访问lockoutTime会返回一个异常,指出它找不到属性。唯一可以远程工作的是
user.InvokeGet(“ IsAccountLocked”)
呼叫,但无论帐户是否被锁定,它总是返回false。
如果有人有任何想法,那将非常有帮助,或者可能会有帮助的链接。
谢谢
如果使用的是.NET 3.5,则应使用System.DirectoryServices.AccountManagement命名空间中的UserPrincipal类。此类具有IsAccountLockedOut()方法以及用于获取AccountLockOutTime的属性。
using (var context = new PrincipalContext( ContextType.Domain ))
{
using (var user = UserPrincipal.FindByIdentity( context,
IdentityType.SamAccountName,
name ))
{
if (user.IsAccountLockedOut())
{
... your code here...
}
}
}
Run Code Online (Sandbox Code Playgroud)