HttpModuleCollection Class
.NET Framework 3.0
Provides a way to index and retrieve a collection of IHttpModule objects.
Namespace: System.Web
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
The following code 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 IHttpModule objects.
<%@ Page language="VJ#" %>
<%@ Import Namespace = "System.Data" %>
<script runat="server">
// System.Web.HttpModuleCollection.AllKeys;GetKey;CopyTo
void Page_Load(Object sender, System.EventArgs e)
{
// 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.get_Current();
// Get the application object for the current request.
HttpApplication myHttpApplication = myHttpContext.get_ApplicationInstance();
// Get the collection of all HTTPModule objects for the current application.
HttpModuleCollection myHttpModuleCollection =
myHttpApplication.get_Modules();
// Get the name of the HttpModule object at index 1.
String httpModuleName = myHttpModuleCollection.GetKey(1);
get_Response().Write("The name of the HttpModule object at index 1"
+ " is " +"'"+ httpModuleName+"'." + "<br><br>");
String allModules[] = myHttpModuleCollection.get_AllKeys();
// Display the names of all HttpModule objects.
get_Response().Write("<b>The HttpModule objects contained in the "
+ "HttpModuleCollection are:</b><br>");
for(int i=0; i < allModules.get_Length(); i++) {
get_Response().Write("Module" + i + " : "
+ allModules[i] + "<br>");
}
// Copy the HttpModule objects in the collection into an array.
System.Array httpModuleArray = Array.CreateInstance(Object.class.ToType(),
myHttpModuleCollection.get_AllKeys().get_Length());
myHttpModuleCollection.CopyTo(httpModuleArray,0);
get_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.get_Length(); i++) {
get_Response().Write("Module" + i + ": " + httpModuleArray.GetValue(i)
+ "<br>");
}
} // Page_Load
</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>
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
System.Object
System.Collections.Specialized.NameObjectCollectionBase
System.Web.HttpModuleCollection
System.Collections.Specialized.NameObjectCollectionBase
System.Web.HttpModuleCollection
Community Additions
ADD
Show: