ASP.NET page execution order (HttpModule, HttpHandler)

public   class  HelloWorldModule : IHttpModule
{
    
public  HelloWorldModule()
    {
    }

    
public  String ModuleName
    {
        
get  {  return   " HelloWorldModule " ; }
    }

    
//  In the Init function, register for HttpApplication
    
//  events by adding your handlers.
     public   void  Init(HttpApplication application)
    {
        application.BeginRequest 
+=
            (
new  EventHandler( this .Application_BeginRequest));
        application.EndRequest 
+=
            (
new  EventHandler( this .Application_EndRequest));
    }

    
private   void  Application_BeginRequest(Object source,
         EventArgs e)
    {
    
//  Create HttpApplication and HttpContext objects to access
    
//  request and response properties.
        HttpApplication application  =  (HttpApplication)source;
        HttpContext context 
=  application.Context;
        context.Response.Write(
" <h1><font color=red> HelloWorldModule: Beginning of Request</font></h1><hr> " );
    }

    
private   void  Application_EndRequest(Object source, EventArgs e)
    {
        HttpApplication application 
=  (HttpApplication)source;
        HttpContext context 
=  application.Context;
        context.Response.Write(
" <hr><h1><font color=red>HelloWorldModule: End of Request</font></h1> " );
    }

    
public   void  Dispose()
    {
    }
}

    
< system.web >
   
< httpModules >
    
< add name = " HelloWorldModule "  type = " HelloWorldModule " />
   
</ httpModules >
    
</ system.web >

Asp.net process a request
-------------------
HttpModule that must be mastered something
HttpHandler must be mastered something very useful
two or more instances
--- ------------------
ASP.NET event model mechanism

-----------------------
a
customer requests a page is handled by aspnet_isapi.dll this dynamic link library, the request is sent to compile the aspx file to execute CLR and then flows back to the browser Html
--------------------------
two page events
execution order
Page_Init: initialize values or connect
Page_Load: mainly used IsPostBack, the main event was to perform a series of operations to create the first page or asp.net response
caused by the delivery of client-side events too. Prior to this event, the restored page and control view state.
Page_DataBind: at the page level call can also be invoked in a single control.
DataBind_PreRender: data binding pre-rendered, this event is fired just before the view state is saved and render the control.
Page_Unload: This event is to perform final cleanup work.
Non-deterministic events
Page_Error: If an unhandled exception occurs during page processing, then the excitation error events.
Page_AbortTransaction: transaction event, a transaction if the transaction has been aborted This event fires, common shopping cart.
Page_CommitTransaction: If you have successfully fires when a transaction of this event.
-------------------------------------------------- ------
the Global.asax events (execution order)
excited when you start the application: Application_Start
Application_BeginRquest: excitation http request to start
Application_AuthenticateRequest: excited when approving applications http request
Session_Start: Fires when the session starts
Application_EndRequest: excitation at the end of Htttp request
Session_End: excited when the session ends
Application_End: Fires when the application ends
Application_Error: Fires when an error occurs
- --------------------
ISAPI: to insert some web server set up, expand capabilities, enhanced web server functionality.
ISAPI: extension, win32 dynamic link library, such as aspnet_isapi.dll, ISAPI extensions can be seen as a normal application, it deals with the target HTTP request.
ISAPI: filters, web server passes the request to the relevant filter, then the filter may modify the request, performs some operations and the like.
ASP.NET process requested:
the pipes based on models, in which the ASP.NET http request to the pipeline all the modules. Each module receives the HTTP request, and to have full control. Once the HTTP request goes through all the modules, eventually disposed HTTP handler. HTTP handler to request some processing, and the result will again through the HTTP pipeline module modules.
-----------
HttpModule
ISAPI filter (Filter): IIS itself does not support dynamic pages, meaning that he only supports static HTML pages of content for .asp .aspx .cgi .php, etc., IIS does not know how to handle these suffixes it treats it as a text, did not deal sent to the client. To solve this problem, IIS has a mechanism called the ISAPI filter. It is a COM component.
ASP.NET services registered to IIS when the file extension will be processed each extension to IIS registered inside (such as * .ascx * .aspx, etc.). After the expansion initiated, by definition good way to handle file IIS can not handle, then control jumps to process special handling code in, asp.net is aspnet_isapi.dll. Let the process begin processing code, generate standard HTML code, after generating the code added to the original HTML, the last full HTML returned to IIS, IIS then sends the content to the client.
----------------
HttpModule '
the Http module of the functional filter (ISAPI filter), which is realized .net assembly System.Web.IHttpModule interface. . These components by registering itself in certain events, to insert themselves into the ASP.NET request processing pipeline. When these events occur, ASP.NET calls are interested in the HTTP request module, so the module can process the request. Sometimes need to worry too much about the http request, note that it is not covered by other systems include built-in HttpModule, the configuration in Machine.config.
--------------------------------------
HttpHandler
It implements the ISAPI Extention function, which processes information and sending the response (the Response) request (Request) a. By HttpHandler IHttpHandler function must implement the interface. HTTP handler is the interface implemented System.Web.IHttpHandler .NET components. Any class that implements this interface can be used to process the incoming Http request. It is Http handler.

In previous time ASP, * .asp page when a requested file, the HTTP request first be intercepted named inetinfo.exe process, this process is actually www service. After it will intercept this request to the asp.dll process, which will explain the asp page, and then explain the data stream back to the client browser. In fact ASP.DLL is a document attached to the IIS ISAPI, which is responsible for the interpretation of the implementation of the file, such as an ASP file, ASA,
etc., ---------------------- ---------------


ASP.NET HTTP request processing method
, with similar, the http request will be intercepted by the inetinfo.exe process (www service), it is judged that the file suffix after asp When a client requests a page * .aspx files to the web server, the request will be forwarded to the ASPNET_ISAPI.DLL and ASPNET_ISAPI.DLL, will be sent to ASPNET_WP.EXE process through a pipeline Http pipeLine this http request, when the HTTP request comes ASPNET_WP.EXE process, asp.net framework will pass HttpRuntime to deal with the Http request, after the processed results back to the client.
------------------------------------
when an http request is sent to HttpRuntime, the Http request will continue to be fed into a container which is called a HttpApplication Factory's, and this will give the vessel a http request HttpApplication instance to handle the incoming transmission, then the http request will turn into the following several containers:
HttpModule ' -> HttpHandler Factory -> HttpHandler
after ProcessRequest method of HttpHandler processed inside the system, the entire Http Request was processed, the client will give the corresponding stuff.
Complete http request processing flow in asp.net framework of:
HttpRequest -> inetinfo.exe-> ASPNET_ISAPI.DLL -> Http Pipeline -> ASPNET_WP.EXE -> HttpRuntime -> HttpApplication Factory -> HttpApplication -> HttpModule -> HttpHandler Factory -> HttpHandler- -> HttpHandler.ProcessRequest ()
If you want to intercept a httpRequest in the middle and do their own processing, it should HttpRuntime running inside to do it, when to do precisely this HttpModule in this container.
----------------------------------------
---------- ---------------------------
system itself to achieve a HttpModule IHttpModule interface, of course, our own classes can be achieved IHttpModule interfaces, which the system can replace the HttpModule objects.
The system default ASP.NET HttpModule:

DefaultAuthenticationModule ensure Authentication object is present context. It can not be inherited.
FileAuthorizationModule verify that the remote user has permission to access the requested NT file. It can not be inherited.
FormsAuthenticationModule enable ASP.NET application to use Forms authentication. It can not be inherited.
PassportAuthenticationModule surround PassportAuthentication provide packaging services. It can not be inherited.
SessionStateModule provides session-state services for the application.
UrlAuthorizationModule provide URL-based authorization service to permit or deny access to specific resources. It can not be inherited.
WindowsAuthenticationModule enable ASP.NET applications to use Windows / IIS authentication. Can not be inherited

--------------------------------------
The system default HttpModule in the machine.config file configuration, and when we use to develop the relationship web.config is: Http request is to start a process of time, it will be followed by a request to load machine.config and web.config files in the directory where the page in ASP.NET FRAMEWORK, if the machine is configured with its own HttpModule, you can still remove out of this mapping in the web.config file is located page. 

 From that information found on the Internet, I feel very important, and would like to leave

Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2011/05/15/2046728.html

Guess you like

Origin blog.csdn.net/weixin_34061555/article/details/93496098