共用方式為


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

備註

當目前的、 或 動作已透過將 屬性設定Canceltrue來取消時,就會FailureInformation使用 屬性。ResetPasswordChangePasswordCreateUser

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

適用於

另請參閱