ValidatePasswordEventArgs.FailureInformation Proprietà

Definizione

Ottiene o imposta un'eccezione che descrive il motivo dell'errore di convalida della password.

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

Valore della proprietà

Oggetto Exception che descrive il motivo dell'errore di convalida della password.

Esempio

Nell'esempio di codice seguente viene illustrato un ValidatingPassword evento che convalida il formato della password per l'utente e annulla l'azione se la password non corrisponde al formato richiesto.

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

Commenti

La FailureInformation proprietà viene utilizzata quando l'azione corrente CreateUser, ChangePasswordo ResetPassword è stata annullata impostando la Cancel proprietà su true.

La FailureInformation proprietà è impostata su un'eccezione che descrive il motivo dell'errore di convalida della password. Il metodo chiamante genererà l'eccezione su cui è impostata la FailureInformation proprietà. Se la FailureInformation proprietà è null, il chiamante genererà un'eccezione di errore di convalida della password generica.

Si applica a

Vedi anche