AuthenticablePrincipal.UnlockAccount 方法

定义

如果当前帐户已锁定,则解锁该帐户。Unlocks the account if it is currently locked out.

public:
 void UnlockAccount();
public void UnlockAccount ();
member this.UnlockAccount : unit -> unit
Public Sub UnlockAccount ()

例外

调用方没有适当的权限。The caller does not have appropriate rights.

- 或 --or-

将更改保存到存储区时发生异常。An exception occurred when saving the changes to the store.

示例

以下示例代码将连接到 LDAP 域 "fabrikam.com",并在构造函数中初始化用户名 (管理员) 和密码 (SecretPwd123) PrincipalContextThe following example code connects to the LDAP domain "fabrikam.com" with the username (administrator) and password (SecretPwd123) initialized in the PrincipalContext constructor.

执行搜索,以在 PrincipalContext 构造函数 "CN = Users,dc = fabrikam,DC = com" 下查找名称为 "John Smith" 的用户。A search is performed to find the user with name "John Smith" under the container specified in the PrincipalContext constructor: "CN=Users,DC=fabrikam,DC=com." 如果找到该用户,则会执行检查以确定此用户的帐户是否已锁定。如果帐户已锁定,则代码示例会解除帐户锁定。If the user is found, a check is performed to determine whether this user's account has been locked out. If the account has been locked out, the code example unlocks the account.

PrincipalContext ctx = new PrincipalContext(ContextType.Domain,   
                                         "fabrikam.com",   
                                         "CN=Users,DC=fabrikam,DC=com",   
                                         "administrator",   
                                         "SecretPwd123");  

UserPrincipal usr = UserPrincipal.FindByIdentity(ctx, "John Smith");  
if (usr != null)  
{  
    if (usr.IsAccountLockedOut())  
        usr.UnlockAccount();  

    usr.Dispose();  
}  
ctx.Dispose();   

适用于