ValidatePasswordEventArgs.FailureInformation 属性

定义

获取或设置描述密码验证失败的原因的异常。

public:
 property Exception ^ FailureInformation { Exception ^ get(); void set(Exception ^ value); };
public Exception FailureInformation { get; set; }
member this.FailureInformation : Exception with get, set
Public Property FailureInformation As Exception

属性值

描述密码验证失败的原因的 Exception

示例

下面的代码示例演示一个 ValidatingPassword 事件,该事件验证用户的密码格式,并在密码与所需格式不匹配时取消操作。

public void Page_Load()
{
  Membership.ValidatingPassword +=
    new MembershipValidatePasswordEventHandler(OnValidatePassword);
}

public void OnValidatePassword(object sender,
                              ValidatePasswordEventArgs args)
{
  System.Text.RegularExpressions.Regex r =
    new System.Text.RegularExpressions.Regex(@"(?=.{6,})(?=(.*\d){1,})(?=(.*\W){1,})");


  if (!r.IsMatch(args.Password))
  {
    args.FailureInformation =
      new HttpException("Password must be at least 6 characters long and " +
                        "contain at least one number and one special character.");
    args.Cancel = true;
  }
}
Public Sub Page_Load()
    AddHandler Membership.ValidatingPassword, _
    New MembershipValidatePasswordEventHandler(AddressOf OnValidatePassword)
End Sub

Public Sub OnValidatePassword(sender As Object, _
                               args As ValidatePasswordEventArgs)
  Dim r As System.Text.RegularExpressions.Regex =  _
    New System.Text.RegularExpressions.Regex("(?=.{6,})(?=(.*\d){1,})(?=(.*\W){1,})")
         

  If Not r.IsMatch(args.Password) Then
    args.FailureInformation = _
      New HttpException("Password must be at least 6 characters long and " & _
                        "contain at least one number and one special character.")
    args.Cancel = True
  End If
End Sub

注解

FailureInformation通过将 属性设置为 true来取消当前 CreateUserChangePasswordResetPassword 操作时,Cancel将使用 属性。

属性 FailureInformation 设置为描述密码验证失败原因的异常。 调用方法将引发 属性设置为 的 FailureInformation 异常。 FailureInformation如果 属性为 null,则调用方将引发泛型密码验证失败异常。

适用于

另请参阅