2

ASP.NET2.0でCreateUserWizardコントロールの動作を修正しようとしています。かなり単純な、すぐに使える実装では、存在しない電子メールアドレスを入力した場合、または電子メールの送信中に他のエラーが発生した場合、SMTPエラーの醜い詳細を示すYSODととにかくユーザーアカウントが作成されます。SendMailErrorの処理は、ユーザーが既に作成されたに発生するため、役に立たないようです。

理想的には、電子メールエラーにより、「無効な電子メールアドレス」エラーメッセージ(またはその効果のあるもの)が表示されます。このように思えるのはかなり簡単なはずですが、かなり見て回った後、答えが見つかりませんでした。誰かが解決策を持っていますか?

4

2 に答える 2

2

これが私がすることです。完璧ではありませんが、役に立ちます。

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;
    }
}
于 2010-11-17T16:26:05.093 に答える
0

そのようにはできません。ほとんどの企業が行っていることを使用する必要があります。X 時間以内にクリックする必要がある確認メールを送信してから、アカウントを作成します。これは、CUW の動作方法からのわずかな変更であるため、基本機能からいくらか離れてイベントを利用し、そのデフォルト機能を防止する必要があります。

HTH。

于 2010-03-02T22:28:22.420 に答える