HttpModule Tester : HTTP Modules « Development « ASP.NET Tutorial






<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="HttpModuleTester" %>

<!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 runat="server">
    <title>HttpModuleTester</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>

File: Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class HttpModuleTester : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpContext myHttpContext = HttpContext.Current;

        HttpApplication myHttpApplication = myHttpContext.ApplicationInstance;

        HttpModuleCollection myHttpModuleCollection = myHttpApplication.Modules;

        for (int index=0; index < myHttpModuleCollection.Count; index++)
        {
            IHttpModule module = myHttpModuleCollection.Get(index);
            Response.Write("Module = " + module.ToString() + "<br>");
        }

        string httpModuleName = myHttpModuleCollection.GetKey(1);
        Response.Write("The name of the HttpModule object at index 1" + " is " + "'" + httpModuleName + "'." + "<br><br>");

        string[] allModules = myHttpModuleCollection.AllKeys;

        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>");
    }
}








9.25.HTTP Modules
9.25.1.Creating Custom HTTP Modules
9.25.2.HttpContext (C#)
9.25.3.HttpContext (VB)
9.25.4.URL rewriting HttpModule (C#)
9.25.5.URL rewriting HttpModule (VB)
9.25.6.The IHttpHandler page template (C#)
9.25.7.The IHttpHandler page template (VB)
9.25.8.Outputting an image from an HttpHandler (C#)
9.25.9.Outputting an image from an HttpHandler (VB)
9.25.10.Adding the HttpHandler configuration information to web.config
9.25.11.HttpModule Tester