这就是我所做的。这并不完美,但它有帮助。
protected void CreateUserWizard1_SendMailError(object sender, SendMailErrorEventArgs e)
{
// e.Exception can be one of the exceptions generated from SmtpClient.Send(MailMessage)
if (e.Exception is SmtpFailedRecipientException)
{
// The message could not be delivered to one or more of the recipients in To, CC, or BCC()()().
// TODO: Set an error message on the page
e.Handled = true;
// Since the user has already been created at this point, we need to remove them.
Membership.DeleteUser(CreateUserWizard1.UserName);
// Set an internal flag for use in the ActiveStepChanged event.
emailFailed = true;
return;
}
}
protected void CreateUserWizard1_ActiveStepChanged(object sender, EventArgs e)
{
if (CreateUserWizard1.ActiveStep != CreateUserWizard1.CompleteStep)
return;
if (emailFailed)
{
// If the email failed, keep the user on the first step.
CreateUserWizard1.ActiveStepIndex = 0;
return;
}
}