Concept: ISAPI server extensions are DLL files that can be loaded and called by HTTP servers.
1. When the Asp.net page initiates a request, IIS receives the request and submits it to the corresponding ASP. Net ISAPI for Processing Based on the suffix of the Request page,
2. ASP. NET isapiann aspnet_wp.exeprocess the request, and upload aspnet_wp.exe(W3wp.exe IIS 6)The execution status of the process.
3.aspnet_wp.exe the main task is to send requests to a series of hosted objects called HTTP Pipelines
An appropriate analogy:
If ASP. NET isapiis used as the sales manager, aspnet_wp.exe is the production manager, and HTTP pipeline is the Production Pipeline.
The supervisor will hand over the order (HTTP request) to the httpruntime team's staff processrequest (httpworkerrequest wr). According to the internal division of labor, httpruntime will eventually be produced in the pipeline by processrequestinternal (httpworkerrequest wr, so processrequestinternal (httpworkerrequest wr) is the focus of our analysis.
Processrequestinternal:
1. Create an httpcontext instance
2. initialize the first request (ensurefirstrequestinit ).
3. Create an httpwriter instance.
4. Call httpapplicationfactory. getapplicationinstance to create an httpapplication instance.
After an httpapplication instance is created, the initinternal method of the instance is called.
The initinternal method provides the following functions:
4.1 initmodules (): Create the corresponding httpmodules according to the settings of Web. config.
4.2 hookupeventhandlersforappplicationandmodules: calls the corresponding event processing function in the httpapplication instance based on the event.
4.3 create many instances of classes that implement the iexecutionstep interface and add them to _ execsteps of the current httpapplication instance, waiting for the callback to be executed.
5. Call the beginprocessrequest of the httpapplication instance to process requests asynchronously.
See: http://www.cnblogs.com/aaa6818162/archive/2009/11/13/1602333.html
1. When an HTTP request is received
2. Obtain the current htttp request information from HTTP. sys through ISAPI in IIS and save the information to the httpworkerrequest class.
3. Isolated applicationsProgramLoad httpruntime in the domain appdomain. Call the processrequest method of httpruntime (method parameter httpworkerrequest)
4. After the HTTP request enters httpruntime
5. httpruntime transfers HTTP requests to httpapplication. httpapplication represents a web application created by a programmer.
Httpapplication creates an httpcontext object for this HTTP request. These objects contain many other objects related to this request, including httprequest, httpresponse, and httpsessionstate. These objects can be accessed through the page class or context class in the program. ,
6. Next, the HTTP request uses a series of modules, which have full control over the HTTP request.
These modules can do things before performing a specific task..
7. After the HTTP request passes through all modules, it will be processed by httphandler.
In this step, perform some actual operations, usually the business logic completed on the. ASPX page.
Public class page: templatecontrol, ihttphandler {
//CodeOmitted
}
As you can see, the page class implements the ihttphandler interface, and httphandler is also the lowest layer for HTTP request processing.
8. After httphandler completes processing, the HTTP request returns to the module again,At this time, the module can do some things after some work has been completed.
9. Then, IIS receives the returned data stream and returns it to HTTP. sys again,
10. Finally, HTTP. sys returns the data to the client browser.
Notes after creating an httpapplication
Both httpmodule and httphandler are loaded and attached to the call chain in part of the httpapplication. INIT () function call.
// Execute the custom initialization code after adding all the event handler modules.
Httpapplication Public Virtual void Init ();
In general
1. initialize each module through the initinternal method of httpapplication
2. Use the buildestep method of applicationstepmanager in httpapplication (create steps in order)
Steps for creating the beginprocessrequest method of 3httpapplication, that is, triggering the lifecycle of httpapplication
Execution relationship between httphandel and httpmodel
Table 1: events triggered by the httpapplication object
| Event |
Remarks |
|
Beginrequest |
Triggered before request processing starts |
|
Authenticaterequest |
Verify the identity of the caller |
|
Authorizerequest |
Perform access check |
|
Resolverequestcache |
Get Response from Cache |
|
Acquirerequeststate |
Load session Status |
|
Prerequesthandlerexecute |
Triggered before the request is about to be sent to the handler object |
|
Postrequesthandlerexecute |
Triggered after the request is just sent to the handler object |
|
Releaserequeststate |
Storage session Status |
|
Updaterequestcache |
Update response Cache |
|
Endrequest |
Triggered after processing |
|
Presendrequestheaders |
Triggered before the cached response header is sent |
|
Presendrequestcontent |
Triggered before the response body of the cache is sent |
Note: The HTTP handler (httphandler) is executed between the prerequesthandlerexecute and postrequesthandlerexecute events.
Is httpapplication created by httpruntime? No. httpruntime only requests httpapplicationfactory to return an httpapplication object. After receiving the request, httpapplicationfactory checks whether there are existing and idle objects. If yes, It retrieves an httpapplication object and returns it to httpruntime. If no, create an httpapplication object to httpruntime.
The implementation of the methods of the httpapplication class will not be explained one by one. If you need to understand it, write an httpapplication word in the class, right-click and choose "go to definition", you can see the metadata in it.
Reference remarks:
ASP. Design Idea http://www.cnblogs.com/aaa6818162/archive/2009/10/30/1592886.html#1688909 of Net
Understanding and deepening understanding of httpapplication http://www.cnblogs.com/whtydn/archive/2009/10/16/1584584.html
Asp.net principle important http://www.cnblogs.com/aaa6818162/archive/2009/11/11/1600987.html