找不到Active Directory中的锁定属性(C#) [英] Cannot find the Locked property in Active Directory (C#)

查看:320
本文介绍了找不到Active Directory中的锁定属性(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我知道已经有关于这一主题的帖子很多然而所有这一切我已经找到了我的情况没有帮助的信息。正在发生的事情是,我无法找到那里的属性是锁定了用户的广告。我已经使用

First off I know there have been many posts on this topic however all of the information that I have found does not help in my situation. What is happening is that I cannot find where the property is for locking out a user in AD. I have used

链接文本

有一切与AD和它的所有工作然而,该位映射如果帐户被锁定在userAccountControl的不改变。试图访问lockoutTime返回一个异常说,它无法找到该属性。该远程操作的唯一的事情就是

for everything else with AD and it has all worked however, the bit map the userAccountControl does not change if an account is locked out. Trying to access the lockoutTime returns an exception saying that it cannot find the property. The only thing that remotely works is the

user.InvokeGet(IsAccountLocked)

user.InvokeGet("IsAccountLocked")

通话,但它始终返回false不管,如果该帐户被锁定或没有。

call, but it always returns false no matter the if the account is locked or not.

如果任何人有任何想法,这将是非常有益的或链接,可以帮助我。

If anybody has any ideas it would be very helpful or a link that might help me out.

感谢

推荐答案

如果您使用的是.NET 3.5,你应该使用<一个href="http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.userprincipal.aspx"相对=nofollow> UserPrincipal 在System.DirectoryServices.AccountManagement命名空间中的类。这个类有一个<一个href="http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.authenticableprincipal.isaccountlockedout.aspx"相对=nofollow> IsAccountLockedOut()方法和属性,以获取<一href="http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.authenticableprincipal.accountlockouttime.aspx"相对=nofollow> AccountLockOutTime 。

If you are using .NET 3.5 you should use the UserPrincipal class in the System.DirectoryServices.AccountManagement namespace. This class has an IsAccountLockedOut() method as well as a property to get the AccountLockOutTime.

using (var context = new PrincipalContext( ContextType.Domain ))
{
     using (var user = UserPrincipal.FindByIdentity( context,
                                                     IdentityType.SamAccountName,
                                                     name ))
     {
          if (user.IsAccountLockedOut())
          {
              ... your code here...
          }
     }
}

这篇关于找不到Active Directory中的锁定属性(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆