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 目前的 CreateUserChangePasswordResetPassword 動作已取消時,將 屬性設定 Canceltrue ,就會使用 屬性。

屬性 FailureInformation 會設定為例外狀況,描述密碼驗證失敗的原因。 呼叫方法會擲回 屬性設定為 的 FailureInformation 例外狀況。 FailureInformation如果 屬性為 null ,呼叫端將會擲回泛型密碼驗證失敗例外狀況。

適用於

另請參閱