两者都能处理HttpApplication中的事件。

IHttpModule 的方式可以用来创建多个 Module ,并编译为程序集,方便部署和在多个项目中使用。
而 Global.asax 方式比较直接,方便在程序中一次性的处理。

Global.asax是继承了HttpApplication。而IHttpModule的Init方法中,传入的参数必须是HttpApplication。

HttpModule可以编译成dll,但是global只能在一个应用程序中。

You can use the Global.asax file to synchronize any event that is exposed by the HttpApplication base class. To do this, you must use the following naming pattern to author methods:

在Global.asax中,如果要实现HttpApplication中暴露的事件,必须采用专用的命名规则。Application_EventName(AppropriateEventArgumentSignature)

protected void Application_AcquireRequestState(object sender, EventArgs e)
        {
            Response.Write("1Application_AcquireRequestState" + "
");
        }
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            Response.Write("2Application_AuthenticateRequest" + "
");
        }
        protected void Application_AuthorizeRequest(object sender, EventArgs e)
        {
            Response.Write("3Application_AuthorizeRequest" + "
");
        }
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            Response.Write("4Application_BeginRequest" + "
");
        }
        protected void Application_Disposed(object sender, EventArgs e)
        {
            Response.Write("5Application_Disposed" + "
");
        }
        protected void Application_EndRequest(object sender, EventArgs e)
        {
            Response.Write("6Application_EndRequest" + "
");
        }
        protected void Application_Error(object sender, EventArgs e)
        {
            Response.Write("7Application_Error" + "
");
        }
        protected void Application_LogRequest(object sender, EventArgs e)
        {
            Response.Write("8Application_LogRequest" + "
");
        }
        protected void Application_MapRequestHandler(object sender, EventArgs e)
        {
            Response.Write("9Application_MapRequestHandler" + "
");
        }
        protected void Application_PostAcquireRequestState(object sender, EventArgs e)
        {
            Response.Write("10Application_PostAcquireRequestState" + "
");
        }
        protected void Application_PostAuthenticateRequest(object sender, EventArgs e)
        {
            Response.Write("11Application_PostAuthenticateRequest" + "
");
        }
        protected void Application_PostAuthorizeRequest(object sender, EventArgs e)
        {
            Response.Write("12Application_PostAuthorizeRequest" + "
");
        }
        protected void Application_PostLogRequest(object sender, EventArgs e)
        {
            Response.Write("13Application_PostLogRequest" + "
");
        }
        protected void Application_PostMapRequestHandler(object sender, EventArgs e)
        {
            Response.Write("14Application_PostMapRequestHandler" + "
");
        }
        protected void Application_PostReleaseRequestState(object sender, EventArgs e)
        {
            Response.Write("15Application_PostReleaseRequestState" + "
");
        }
        protected void Application_PostRequestHandlerExecute(object sender, EventArgs e)
        {
            Response.Write("16Application_PostRequestHandlerExecute" + "
");
        }
        protected void Application_PostResolveRequestCache(object sender, EventArgs e)
        {
            Response.Write("17Application_PostResolveRequestCache" + "
");
        }
        protected void Application_PostUpdateRequestCache(object sender, EventArgs e)
        {
            Response.Write("18Application_PostUpdateRequestCache" + "
");
        }
        protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            Response.Write("19Application_PreRequestHandlerExecute" + "
");
        }
        protected void Application_PreSendRequestContent(object sender, EventArgs e)
        {
            Response.Write("20Application_PreSendRequestContent" + "
");
        }
        protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
        {
            Response.Write("21Application_PreSendRequestHeaders" + "
");
        }
        protected void Application_ReleaseRequestState(object sender, EventArgs e)
        {
            Response.Write("22Application_ReleaseRequestState" + "
");
        }
        protected void Application_ResolveRequestCache(object sender, EventArgs e)
        {
            Response.Write("23Application_ResolveRequestCache" + "
");
        }
        protected void Application_UpdateRequestCache(object sender, EventArgs e)
        {
            Response.Write("24Application_UpdateRequestCache" + "
");
        }