Global.asax和IHttpModule

两者都能处理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" + "<br>");
        }
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            Response.Write("2Application_AuthenticateRequest" + "<br>");
        }
        protected void Application_AuthorizeRequest(object sender, EventArgs e)
        {
            Response.Write("3Application_AuthorizeRequest" + "<br>");
        }
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            Response.Write("4Application_BeginRequest" + "<br>");
        }
        protected void Application_Disposed(object sender, EventArgs e)
        {
            Response.Write("5Application_Disposed" + "<br>");
        }
        protected void Application_EndRequest(object sender, EventArgs e)
        {
            Response.Write("6Application_EndRequest" + "<br>");
        }
        protected void Application_Error(object sender, EventArgs e)
        {
            Response.Write("7Application_Error" + "<br>");
        }
        protected void Application_LogRequest(object sender, EventArgs e)
        {
            Response.Write("8Application_LogRequest" + "<br>");
        }
        protected void Application_MapRequestHandler(object sender, EventArgs e)
        {
            Response.Write("9Application_MapRequestHandler" + "<br>");
        }
        protected void Application_PostAcquireRequestState(object sender, EventArgs e)
        {
            Response.Write("10Application_PostAcquireRequestState" + "<br>");
        }
        protected void Application_PostAuthenticateRequest(object sender, EventArgs e)
        {
            Response.Write("11Application_PostAuthenticateRequest" + "<br>");
        }
        protected void Application_PostAuthorizeRequest(object sender, EventArgs e)
        {
            Response.Write("12Application_PostAuthorizeRequest" + "<br>");
        }
        protected void Application_PostLogRequest(object sender, EventArgs e)
        {
            Response.Write("13Application_PostLogRequest" + "<br>");
        }
        protected void Application_PostMapRequestHandler(object sender, EventArgs e)
        {
            Response.Write("14Application_PostMapRequestHandler" + "<br>");
        }
        protected void Application_PostReleaseRequestState(object sender, EventArgs e)
        {
            Response.Write("15Application_PostReleaseRequestState" + "<br>");
        }
        protected void Application_PostRequestHandlerExecute(object sender, EventArgs e)
        {
            Response.Write("16Application_PostRequestHandlerExecute" + "<br>");
        }
        protected void Application_PostResolveRequestCache(object sender, EventArgs e)
        {
            Response.Write("17Application_PostResolveRequestCache" + "<br>");
        }
        protected void Application_PostUpdateRequestCache(object sender, EventArgs e)
        {
            Response.Write("18Application_PostUpdateRequestCache" + "<br>");
        }
        protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            Response.Write("19Application_PreRequestHandlerExecute" + "<br>");
        }
        protected void Application_PreSendRequestContent(object sender, EventArgs e)
        {
            Response.Write("20Application_PreSendRequestContent" + "<br>");
        }
        protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
        {
            Response.Write("21Application_PreSendRequestHeaders" + "<br>");
        }
        protected void Application_ReleaseRequestState(object sender, EventArgs e)
        {
            Response.Write("22Application_ReleaseRequestState" + "<br>");
        }
        protected void Application_ResolveRequestCache(object sender, EventArgs e)
        {
            Response.Write("23Application_ResolveRequestCache" + "<br>");
        }
        protected void Application_UpdateRequestCache(object sender, EventArgs e)
        {
            Response.Write("24Application_UpdateRequestCache" + "<br>");
        }

你可能感兴趣的:(职场,应用程序,休闲,IHttpModule,global.asax)