CreateUserWizard.OnSendMailError(SendMailErrorEventArgs) 方法

定义

当无法向新用户发送电子邮件时引发 SendMailError 事件。

protected:
 virtual void OnSendMailError(System::Web::UI::WebControls::SendMailErrorEventArgs ^ e);
protected virtual void OnSendMailError (System.Web.UI.WebControls.SendMailErrorEventArgs e);
abstract member OnSendMailError : System.Web.UI.WebControls.SendMailErrorEventArgs -> unit
override this.OnSendMailError : System.Web.UI.WebControls.SendMailErrorEventArgs -> unit
Protected Overridable Sub OnSendMailError (e As SendMailErrorEventArgs)

参数

e
SendMailErrorEventArgs

包含事件数据的 SendMailErrorEventArgs

示例

下面的代码示例定义一个自定义 CreateUserWizard 对象,该对象将电子邮件错误记录到特定于站点的日志记录函数。

using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls {

  [AspNetHostingPermission (SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  public class CustomCreateUserWizard : CreateUserWizard
  {
    private void SiteSpecificErrorLoggingProcedure (SendMailErrorEventArgs e)
    {
      // Site-specific code for logging email errors goes here.
    }

    protected override void OnSendMailError (SendMailErrorEventArgs e)
    {
      this.SiteSpecificErrorLoggingProcedure (e);
      e.Handled = true;
    }
  }
}
Imports System.Web
Imports System.Web.UI.WebControls
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls
  <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public Class CustomCreateUserWizard
    Inherits CreateUserWizard

    Private Sub SiteSpecificErrorLoggingProcedure(ByVal e As SendMailErrorEventArgs)
      ' Site-specific code for logging email errors goes here.
    End Sub
    
    Overloads Sub OnSendMailError(ByVal e As SendMailErrorEventArgs)
      Me.SiteSpecificErrorLoggingProcedure(e)
      e.Handled = True
    End Sub
  End Class
End Namespace

下面的代码示例演示了使用 的 CustomCreateUserWizard网页。

<%@ Page Language="C#"%>
<%@ Import namespace="Samples.AspNet.CS.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  void Page_Load (object sender, EventArgs e)
  {
    CustomCreateUserWizard createUser = new CustomCreateUserWizard ();
    Placeholder1.Controls.Add (createUser);
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CreateUserWizard.OnSendMailError sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:placeholder id="Placeholder1" runat="server">
      </asp:placeholder>
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB"%>
<%@ Import namespace="Samples.AspNet.VB.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim createUser As New CustomCreateUserWizard
    Placeholder1.Controls.Add(createUser)
  End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>
      CreateUserWizard.OnSendMailError sample</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <div>
        <asp:placeholder id="Placeholder1" runat="server">
        </asp:placeholder>
      </div>
    </form>
  </body>
</html>

注解

OnSendMailError当 SMTP 邮件系统在尝试向新用户发送电子邮件时引发异常时,将调用 方法。

Exception检查作为 e 参数传递的 SendMailErrorEventArgs 对象的 属性,以确定异常的实际原因。 最常见的问题是 Web.config 文件的 部分出现配置错误 <smtpMail>

必须设置Handled作为 e 参数传递的 SendMailErrorEventArgs 对象的 属性,以指示已处理导致调用 方法的OnSendMailError异常,否则将重新引发异常。

引发事件时,将通过委托调用事件处理程序。 有关详细信息,请参阅 处理和引发事件

OnSendMailError 方法还允许派生类对事件进行处理而不必附加委托。 这是在派生类中处理事件的首选技术。

继承者说明

在派生类中重写 OnSendMailError(SendMailErrorEventArgs) 时,请务必调用基类的 OnSendMailError(SendMailErrorEventArgs) 方法,以便注册的委托接收事件。

适用于

另请参阅