EmbeddedMailObjectsCollection 类

定义

表示有序的 EmbeddedMailObject 对象集。Represents an ordered set of EmbeddedMailObject objects.

public ref class EmbeddedMailObjectsCollection sealed : System::Collections::CollectionBase
public sealed class EmbeddedMailObjectsCollection : System.Collections.CollectionBase
type EmbeddedMailObjectsCollection = class
    inherit CollectionBase
Public NotInheritable Class EmbeddedMailObjectsCollection
Inherits CollectionBase
继承
EmbeddedMailObjectsCollection

示例

下面的代码示例演示了一个使用 Web 控件的 ASP.NET 页面 ChangePassword ,并包含名为的事件的事件处理程序 SendingMail SendingMailThe following code example demonstrates an ASP.NET page that uses a ChangePassword Web control, and includes an event handler for the SendingMail event named SendingMail. 此代码示例假定已将 ASP.NET 网站配置为使用 ASP.NET 成员身份和窗体身份验证,并且已创建一个用户知道其名称和密码。The code example assumes that the ASP.NET Web site has been configured to use ASP.NET membership and Forms authentication, and that a user has been created whose name and password are known to you. 有关详细信息,请参阅 如何:实现简单的窗体身份验证For more information, see How to: Implement Simple Forms Authentication.

如果密码更改成功, SendingMail 事件处理程序中的代码会尝试向用户发送一封电子邮件,以确认所做的更改。If the password change succeeds, the code in the SendingMail event handler attempts to send an email message to the user to confirm the change. 为了使此代码示例正常运行,必须已在服务器上配置 SMTP。SMTP must already be configured on the server in order for this code example to work. 有关如何配置 SMTP 服务器的信息,请参阅 如何:在 IIS 6.0 中安装和配置 Smtp 虚拟服务器For information about how to configure an SMTP server, see How to: Install and Configure SMTP Virtual Servers in IIS 6.0. 出于本示例的目的,不需要配置 SMTP 服务器;该示例构造为测试发送电子邮件失败的情况。For the purposes of this example, it is not necessary to configure an SMTP server; the example is constructed to test for a failure to send an email message.

如果邮件服务器配置不正确或发生其他错误,并且无法发送电子邮件,则 SendMailError 调用该函数。If a mail server is not configured correctly or some other error occurs and the email message cannot be sent, the SendMailError function is called. 向用户显示一条消息。A message is displayed to the user. 此外,将事件记录到 Windows 应用程序事件日志中,假定名为 MySamplesSite 的事件源已存在。In addition, an event is logged to the Windows Application event log with the assumption that an event source named MySamplesSite already exists. 请参阅下面的代码示例,以创建指定的事件源。See the code example below to create the specified event source. 有关创建事件源的详细信息,请参阅 ASP.NET Web 窗体页中的服务器事件处理For more information about creating an event source, see Server Event Handling in ASP.NET Web Forms Pages. Handled对象的属性 SendMailErrorEventArgs 设置为 true ,以指示已处理错误。The Handled property of the SendMailErrorEventArgs object is set to true to indicate that the error has been handled.

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void MySendingMail(object sender, MailMessageEventArgs e)
  {
    Message1.Text = "Sent mail to you to confirm the password change.";
  }

  void MySendMailError(object sender, SendMailErrorEventArgs e)
  {
    Message1.Text = "Could not send email to confirm password change.";

    // The MySamplesSite event source has already been created by an administrator.
    System.Diagnostics.EventLog myLog = new System.Diagnostics.EventLog();
    myLog.Log = "Application";
    myLog.Source = "MySamplesSite";
    myLog.WriteEntry(
        "Sending mail via SMTP failed with the following error: " + 
        e.Exception.Message.ToString(), 
        System.Diagnostics.EventLogEntryType.Error);

    e.Handled = true;
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>ChangePassword including a SendMailError Event</title>
</head>
<body>
  <form id="form1" runat="server">
  <div style="text-align:center">

    <h1>ChangePassword</h1>
    
    <asp:LoginView ID="LoginView1" Runat="server" 
      Visible="true">
      <LoggedInTemplate>
        <asp:LoginName ID="LoginName1" Runat="server" FormatString="You are logged in as {0}." />
        <br />
      </LoggedInTemplate>
      <AnonymousTemplate>
        You are not logged in
      </AnonymousTemplate>
    </asp:LoginView><br />
    
    <asp:ChangePassword ID="ChangePassword1" Runat="server"
      BorderStyle="Solid" 
      BorderWidth="1" 
      CancelDestinationPageUrl="~/Default.aspx" 
      DisplayUserName="true"
      OnSendingMail="MySendingMail" 
      OnSendMailError="MySendMailError" 
      ContinueDestinationPageUrl="~/Default.aspx" >
      <MailDefinition 
        BodyFileName="~\MailFiles\ChangePasswordMail.htm" 
        Subject="Activity information for you">
        <EmbeddedObjects>
          <asp:EmbeddedMailObject Name="LoginGif" Path="~\MailFiles\Login.gif" />
          <asp:EmbeddedMailObject Name="PrivacyNoticeTxt" Path="~\MailFiles\PrivacyNotice.txt" />
        </EmbeddedObjects>
      </MailDefinition>
    </asp:ChangePassword><br />
  
    <asp:Label ID="Message1" Runat="server" ForeColor="Red" /><br />

    <asp:HyperLink ID="HyperLink1" Runat="server" 
      NavigateUrl="~/Default.aspx">
      Home
    </asp:HyperLink>
    
  </div>
  </form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  Public Sub MySendingMail(ByVal Sender As Object, ByVal e As MailMessageEventArgs)
    Message1.Text = "Sent mail to you to confirm the password change."
  End Sub

  Public Sub MySendMailError(ByVal Sender As Object, ByVal e As SendMailErrorEventArgs)
    Message1.Text = "Could not send mail to confirm the password change."
    
    ' The MySamplesSite event source has already been created by an administrator.
    Dim myLog As System.Diagnostics.EventLog
    myLog = new System.Diagnostics.EventLog
    myLog.Log = "Application"
    myLog.Source = "MySamplesSite"
    myLog.WriteEntry("Sending mail via SMTP failed with the following error: " & e.Exception.Message.ToString(), System.Diagnostics.EventLogEntryType.Error)

    e.Handled = True
    
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>ChangePassword including a SendMailError Event</title>
</head>
<body>
  <form id="form1" runat="server">
  <div style="text-align:center">

    <h1>ChangePassword</h1>
    
    <asp:LoginView ID="LoginView1" Runat="server" 
      Visible="true">
      <LoggedInTemplate>
        <asp:LoginName ID="LoginName1" Runat="server" FormatString="You are logged in as {0}." />
        <br />
      </LoggedInTemplate>
      <AnonymousTemplate>
        You are not logged in
      </AnonymousTemplate>
    </asp:LoginView><br />
    
    <asp:ChangePassword ID="ChangePassword1" Runat="server"
      BorderStyle="Solid" 
      BorderWidth="1" 
      CancelDestinationPageUrl="~/Default.aspx" 
      DisplayUserName="true"
      OnSendingMail="MySendingMail" 
      OnSendMailError="MySendMailError" 
      ContinueDestinationPageUrl="~/Default.aspx" >
      <MailDefinition 
        BodyFileName="~\MailFiles\ChangePasswordMail.htm" 
        Subject="Activity information for you">
        <EmbeddedObjects>
          <asp:EmbeddedMailObject Name="LoginGif" Path="~\MailFiles\Login.gif" />
          <asp:EmbeddedMailObject Name="PrivacyNoticeTxt" Path="~\MailFiles\PrivacyNotice.txt" />
        </EmbeddedObjects>
      </MailDefinition>
    </asp:ChangePassword><br />
  
    <asp:Label ID="Message1" Runat="server" ForeColor="Red" /><br />

    <asp:HyperLink ID="HyperLink1" Runat="server" 
      NavigateUrl="~/Default.aspx">
      Home
    </asp:HyperLink>
    
  </div>
  </form>
</body>
</html>

如果需要以编程方式将名为 MySamplesSite 的事件源添加到应用程序日志,请使用以下代码示例。Use the following code example if you need to programmatically add the event source named MySamplesSite to your Application log. 要使第一个代码示例正常工作,必须存在此事件源。This event source must exist in order for the first code example to work correctly. 下面的代码示例需要管理员权限。The following code example requires Administrator privileges.

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

#endregion

namespace CreateEventSource
{
    class Program
    {
        static void Main(string[] args)
        {

            try
            {
                // Create the source, if it does not already exist.
                if (!EventLog.SourceExists("MySamplesSite"))
                {
                    EventLog.CreateEventSource("MySamplesSite", "Application");
                    Console.WriteLine("Creating Event Source");
                }

                // Create an EventLog instance and assign its source.
                EventLog myLog = new EventLog();
                myLog.Source = "MySamplesSite";

                // Write an informational entry to the event log.    
                myLog.WriteEntry("Testing writing to event log.");

                Console.WriteLine("Message written to event log.");
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception:");
                Console.WriteLine("{0}", e.ToString());
            }
        }
    }
}
Imports System.Collections.Generic
Imports System.Text
Imports System.Diagnostics


Namespace CreateEventSource
  Class Program
    Sub Main()

        Try
            ' Create the source, if it does not already exist.
            If Not (EventLog.SourceExists("MySamplesSite")) Then
                EventLog.CreateEventSource("MySamplesSite", "Application")
                Console.WriteLine("Creating Event Source")
            End If

            ' Create an EventLog instance and assign its source.
            Dim myLog As New EventLog
            myLog.Source = "MySamplesSite"

            ' Write an informational entry to the event log.
            myLog.WriteEntry("Testing writing to event log.")

            Console.WriteLine("Message written to event log.")
        Catch e As Exception
            Console.WriteLine("Exception:")
            Console.WriteLine(e.ToString)
        End Try

    End Sub
  End Class
End Namespace

下面的示例代码可用作前面的示例代码的 ChangePasswordMail.htm 文件。The following example code can be used as the ChangePasswordMail.htm file for the preceding example code.

重要

在电子邮件中发送用户帐户名或密码是潜在的安全威胁。Sending user account names or passwords in email is a potential security threat. 电子邮件通常以纯文本方式发送,可由特殊网络 "探查" 应用程序读取。Email messages are typically sent in plain text and can be read by special network "sniffing" applications. 若要提高安全性,请使用 保护登录控件中所述的缓解措施。To improve security, use the mitigations that are described in Securing Login Controls.

<html>  
<head><title></title></head>  
<body>  
<form>  

  <h1>Your password for the account named &quot;<%Username%>&quot; has changed.</h1>  

  <p>  
  If you did not initiate this change, please call 1-206-555-0100.  
  </p>  

  <p>  
  <a href="http://www.contoso.com/login.aspx">  
    <img src="cid:LoginGif" alt="Log In" />  
  </a>   
  </p>  

  <p>  
  Please read our attached Privacy Notice.  
  </p>  

</form>  
</body>  
</html>  

注解

EmbeddedMailObjectsCollection存储对将嵌入在电子邮件中的项的引用。The EmbeddedMailObjectsCollection stores references to items that will be embedded in an email message. 嵌入项可以是图像文件(如公司徽标)。The embedded items can be image files such as company logos. EmbeddedMailObjectsCollection由对象的属性使用 EmbeddedObjects MailDefinitionThe EmbeddedMailObjectsCollection is used by the EmbeddedObjects property of the MailDefinition object.

通过以声明方式设置允许嵌入对象属性的电子邮件,可在以下 Web 控件中进行配置 MailDefinitionEmail messages that allow embedded objects are configurable in the following Web controls by setting their MailDefinition properties declaratively:

备注

和对象中的 EmbeddedMailObjectEmbeddedMailObjectsCollection 不会存储在视图状态中。The values in the EmbeddedMailObject and EmbeddedMailObjectsCollection objects are not stored in view state. 这可以防止恶意用户发现服务器的路径信息。This protects against malicious users discovering path information for your server.

构造函数

EmbeddedMailObjectsCollection()

初始化 EmbeddedMailObjectsCollection 类的新实例。Initializes a new instance of the EmbeddedMailObjectsCollection class.

属性

Capacity

获取或设置 CollectionBase 可包含的元素数。Gets or sets the number of elements that the CollectionBase can contain.

(继承自 CollectionBase)
Count

获取 CollectionBase 实例中包含的元素数。Gets the number of elements contained in the CollectionBase instance. 不能重写此属性。This property cannot be overridden.

(继承自 CollectionBase)
InnerList

获取一个 ArrayList,它包含 CollectionBase 实例中元素的列表。Gets an ArrayList containing the list of elements in the CollectionBase instance.

(继承自 CollectionBase)
Item[Int32]

返回一个 EmbeddedMailObjectsCollection 中的某个特定元素,该元素由其位置来标识。Returns a specific element of a EmbeddedMailObjectsCollection, identified by its position.

List

获取一个 IList,它包含 CollectionBase 实例中元素的列表。Gets an IList containing the list of elements in the CollectionBase instance.

(继承自 CollectionBase)

方法

Add(EmbeddedMailObject)

EmbeddedMailObject 添加到 EmbeddedMailObjectsCollection 集合的末尾。Adds an EmbeddedMailObject to the end of the EmbeddedMailObjectsCollection collection.

Clear()

CollectionBase 实例移除所有对象。Removes all objects from the CollectionBase instance. 不能重写此方法。This method cannot be overridden.

(继承自 CollectionBase)
Contains(EmbeddedMailObject)

确定 EmbeddedMailObjectsCollection 是否包含特定的 EmbeddedMailObjectDetermines whether the EmbeddedMailObjectsCollection contains a specific EmbeddedMailObject.

CopyTo(EmbeddedMailObject[], Int32)

将集合中的对象复制到一个一维的 Array 实例(从数组的指定索引处开始)。Copies the collection objects to a one-dimensional Array instance beginning at the specified index in the array.

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetEnumerator()

返回循环访问 CollectionBase 实例的枚举器。Returns an enumerator that iterates through the CollectionBase instance.

(继承自 CollectionBase)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IndexOf(EmbeddedMailObject)

确定 EmbeddedMailObject 中特定 EmbeddedMailObjectsCollection 的索引。Determines the index of a specific EmbeddedMailObject in the EmbeddedMailObjectsCollection.

Insert(Int32, EmbeddedMailObject)

EmbeddedMailObject 对象中的指定索引处插入一个 EmbeddedMailObjectsCollectionInserts an EmbeddedMailObject into the EmbeddedMailObjectsCollection object at the specified index position.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
OnClear()

清除 CollectionBase 实例的内容时执行其他自定义进程。Performs additional custom processes when clearing the contents of the CollectionBase instance.

(继承自 CollectionBase)
OnClearComplete()

在清除 CollectionBase 实例的内容之后执行其他自定义进程。Performs additional custom processes after clearing the contents of the CollectionBase instance.

(继承自 CollectionBase)
OnInsert(Int32, Object)

在向 CollectionBase 实例中插入新元素之前执行其他自定义进程。Performs additional custom processes before inserting a new element into the CollectionBase instance.

(继承自 CollectionBase)
OnInsertComplete(Int32, Object)

在向 CollectionBase 实例中插入新元素之后执行其他自定义进程。Performs additional custom processes after inserting a new element into the CollectionBase instance.

(继承自 CollectionBase)
OnRemove(Int32, Object)

当从 CollectionBase 实例移除元素时执行其他自定义进程。Performs additional custom processes when removing an element from the CollectionBase instance.

(继承自 CollectionBase)
OnRemoveComplete(Int32, Object)

在从 CollectionBase 实例中移除元素之后执行其他自定义进程。Performs additional custom processes after removing an element from the CollectionBase instance.

(继承自 CollectionBase)
OnSet(Int32, Object, Object)

当在 CollectionBase 实例中设置值之前执行其他自定义进程。Performs additional custom processes before setting a value in the CollectionBase instance.

(继承自 CollectionBase)
OnSetComplete(Int32, Object, Object)

当在 CollectionBase 实例中设置值后执行其他自定义进程。Performs additional custom processes after setting a value in the CollectionBase instance.

(继承自 CollectionBase)
OnValidate(Object)

当验证值时执行其他自定义进程。Performs additional custom processes when validating a value.

(继承自 CollectionBase)
Remove(EmbeddedMailObject)

EmbeddedMailObject 中移除指定的 EmbeddedMailObjectsCollection 的第一个匹配项。Removes the first occurrence of the specified EmbeddedMailObject from the EmbeddedMailObjectsCollection.

RemoveAt(Int32)

移除 CollectionBase 实例的指定索引处的元素。Removes the element at the specified index of the CollectionBase instance. 此方法不可重写。This method is not overridable.

(继承自 CollectionBase)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

ICollection.CopyTo(Array, Int32)

从目标数组的指定索引处开始将整个 CollectionBase 复制到兼容的一维 ArrayCopies the entire CollectionBase to a compatible one-dimensional Array, starting at the specified index of the target array.

(继承自 CollectionBase)
ICollection.IsSynchronized

获取一个值,该值指示是否同步对 CollectionBase 的访问(线程安全)。Gets a value indicating whether access to the CollectionBase is synchronized (thread safe).

(继承自 CollectionBase)
ICollection.SyncRoot

获取可用于同步对 CollectionBase 的访问的对象。Gets an object that can be used to synchronize access to the CollectionBase.

(继承自 CollectionBase)
IList.Add(Object)

将对象添加到 CollectionBase 的结尾处。Adds an object to the end of the CollectionBase.

(继承自 CollectionBase)
IList.Contains(Object)

确定 CollectionBase 是否包含特定元素。Determines whether the CollectionBase contains a specific element.

(继承自 CollectionBase)
IList.IndexOf(Object)

搜索指定的 Object,并返回整个 CollectionBase 中第一个匹配项的从零开始的索引。Searches for the specified Object and returns the zero-based index of the first occurrence within the entire CollectionBase.

(继承自 CollectionBase)
IList.Insert(Int32, Object)

将元素插入 CollectionBase 的指定索引处。Inserts an element into the CollectionBase at the specified index.

(继承自 CollectionBase)
IList.IsFixedSize

获取一个值,该值指示 CollectionBase 是否具有固定大小。Gets a value indicating whether the CollectionBase has a fixed size.

(继承自 CollectionBase)
IList.IsReadOnly

获取一个值,该值指示 CollectionBase 是否为只读。Gets a value indicating whether the CollectionBase is read-only.

(继承自 CollectionBase)
IList.Item[Int32]

获取或设置指定索引处的元素。Gets or sets the element at the specified index.

(继承自 CollectionBase)
IList.Remove(Object)

CollectionBase 中移除特定对象的第一个匹配项。Removes the first occurrence of a specific object from the CollectionBase.

(继承自 CollectionBase)

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于

另请参阅