This documentation is archived and is not being maintained.
HttpModuleCollection Class
.NET Framework 1.1
Provides a means of indexing and retrieving a collection of IHttpModule objects.
For a list of all members of this type, see HttpModuleCollection Members.
System.Object
System.Collections.Specialized.NameObjectCollectionBase
System.Web.HttpModuleCollection
[Visual Basic] NotInheritable Public Class HttpModuleCollection Inherits NameObjectCollectionBase [C#] public sealed class HttpModuleCollection : NameObjectCollectionBase [C++] public __gc __sealed class HttpModuleCollection : public NameObjectCollectionBase [JScript] public class HttpModuleCollection extends NameObjectCollectionBase
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Example
[Visual Basic] ' The following example demontrates the AllKeys property, and the GetKey and ' CopyTo methods of the HttpModuleCollection class. The example gets the ' application object for the current request from the current HttpContext ' object. It then extracts the HttpModuleCollection object from the ' application instance and displays the names of the HttpModule objects. ' 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 [C#] // The following example demonstrates the AllKeys property and the GetKey and // CopyTo methods of the HttpModuleCollection class. The example gets the // application object for the current request from the current HttpContext // object. It then extracts the HttpModuleCollection object from the // application instance and displays the names of the HttpModule objects. // 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>");
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Web
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
Assembly: System.Web (in System.Web.dll)
See Also
Show: