HttpModuleCollection 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供一种方法,用以索引并检索 IHttpModule 对象的集合。
public ref class HttpModuleCollection sealed : System::Collections::Specialized::NameObjectCollectionBasepublic sealed class HttpModuleCollection : System.Collections.Specialized.NameObjectCollectionBasetype HttpModuleCollection = class
    inherit NameObjectCollectionBasePublic NotInheritable Class HttpModuleCollection
Inherits NameObjectCollectionBase- 继承
示例
下面的代码示例演示 AllKeys 类的属性和 GetKey 方法和 CopyTo 方法 HttpModuleCollection 。 该示例从当前对象获取当前 HttpContext 请求的应用程序对象。 然后,它将从应用程序实例中提取 HttpModuleCollection 对象,并显示对象的名称 IHttpModule 。
<%@ Page language="C#" %>
<%@ Import Namespace = "System.Data"  %>
<script runat="server">
// System.Web.HttpModuleCollection.AllKeys;GetKey;CopyTo
void Page_Load(object sender, System.EventArgs e)
{
    // Get the HttpContext object for the current request.
    HttpContext myHttpContext = HttpContext.Current;
    // Get the application object for the current request.
    HttpApplication myHttpApplication = myHttpContext.ApplicationInstance;
    // Get the collection of all HTTPModule objects for the current application.
    HttpModuleCollection myHttpModuleCollection = myHttpApplication.Modules;
    // Get the name of the HttpModule object at index 1.
    string httpModuleName = myHttpModuleCollection.GetKey(1);
    Response.Write("The name of the HttpModule object at index 1" + " is " +"'"+  httpModuleName+"'." + "<br><br>"); 
    string[] allModules = myHttpModuleCollection.AllKeys;
    // Display the names of all HttpModule objects.
    Response.Write("<b>The HttpModule objects contained in the HttpModuleCollection are:</b><br>");
    for(int i=0; i < allModules.Length; i++)
       Response.Write("Module" + i + "  : " + allModules[i] + "<br>");
    // Copy the HttpModule objects in the collection into an array.
    System.Array httpModuleArray = Array.CreateInstance(typeof(object),myHttpModuleCollection.AllKeys.Length);
    myHttpModuleCollection.CopyTo(httpModuleArray,0);
    Response.Write("<br><br><b>Successfully copied the HttpModule objects in the HttpModuleCollection to an array."+
       "<br>Displaying the HttpModule objects in array:</b><br>");
    for(int i=0; i < httpModuleArray.Length; i++)
       Response.Write("Module" + i + ": " + httpModuleArray.GetValue(i) + "<br>");
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>HttpModuleCollection Example</title>
</head>
<body>
</body>
</html>
<%@ Page language="VB" %>
<%@ Import Namespace = "System.Data"  %>
<script runat="server">
' System.Web.HttpModuleCollection.AllKeys;GetKey;CopyTo
Sub Page_Load(Sender As Object, e As EventArgs )
' Get the HttpContext object for the current request.
Dim i As Integer
Dim myHttpContext As HttpContext  = HttpContext.Current
' Get the application object for the current request.
Dim  myHttpApplication As HttpApplication = myHttpContext.ApplicationInstance
' Get the collection of all HTTPModule objects for the current application.
Dim myHttpModuleCollection As HttpModuleCollection = myHttpApplication.Modules
       
' Get the name of the HttpModule object at index 1.
Dim httpModuleName As string = myHttpModuleCollection.GetKey(1)
Response.Write("The name of the HttpModule object at index 1" + " is " +"'"+  httpModuleName+"'." + "<br><br>")
      
Dim  allModules() As string = myHttpModuleCollection.AllKeys
      
' Display the names of all HttpModule objects.
Response.Write("<b>The HttpModule objects of HttpModuleCollection are:</b><br>")
For i = 0 To allModules.Length -1 
   Response.Write("Module" + i.ToString() + "  : " + allModules(i).ToString() + "<br>")
Next i
' Copy the HttpModule objects in the collection into an array.    
Dim httpModuleArray As System.Array = Array.CreateInstance(GetType(object),myHttpModuleCollection.AllKeys.Length)
myHttpModuleCollection.CopyTo(httpModuleArray,0)
Response.Write("<br><br><b>Successfully copied the HttpModule objects in the HttpModuleCollection to an array."+ "<br>Displaying the HttpModule objects in the array:</b><br>")
For i=0 To httpModuleArray.Length -1
   Response.Write("Module" + i.ToString() + ": " + httpModuleArray.GetValue(i).ToString() + "<br>")
Next i
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>HttpModuleCollection Example</title>
</head>
<body>
</body>
</html>
属性
| AllKeys | 获取一个包含 HttpModuleCollection 中所有键(模块名称)的字符串数组。 | 
| Count | 获取包含在 NameObjectCollectionBase 实例中的键/值对的数目。(继承自 NameObjectCollectionBase) | 
| IsReadOnly | 获取或设置一个值,通过该值指示 NameObjectCollectionBase 实例是否为只读的。(继承自 NameObjectCollectionBase) | 
| Item[Int32] | 从 HttpModuleCollection 中获取具有指定数字索引的 IHttpModule 对象。 | 
| Item[String] | 从 HttpModuleCollection 获取具有指定名称的 IHttpModule 对象。 | 
| Keys | 获取包含 NameObjectCollectionBase.KeysCollection 实例中所有键的 NameObjectCollectionBase 实例。(继承自 NameObjectCollectionBase) | 
方法
显式接口实现
| ICollection.CopyTo(Array, Int32) | 从目标数组的指定索引处开始将整个 NameObjectCollectionBase 复制到兼容的一维 Array。(继承自 NameObjectCollectionBase) | 
| ICollection.IsSynchronized | 获取一个值,该值指示对 NameObjectCollectionBase 对象的访问是否同步(线程安全)。(继承自 NameObjectCollectionBase) | 
| ICollection.SyncRoot | 获取一个对象,该对象可用于同步对 NameObjectCollectionBase 对象的访问。(继承自 NameObjectCollectionBase) | 
扩展方法
| Cast<TResult>(IEnumerable) | 将 IEnumerable 的元素强制转换为指定的类型。 | 
| OfType<TResult>(IEnumerable) | 根据指定类型筛选 IEnumerable 的元素。 | 
| AsParallel(IEnumerable) | 启用查询的并行化。 | 
| AsQueryable(IEnumerable) | 将 IEnumerable 转换为 IQueryable。 |