Asp.net processing process

Source: Internet
Author: User

Original article: http://www.cnblogs.com/wupeiqi/archive/2013/03/03/2941295.html

Working Process:

In iis, the workflow (w3wp.exe) runs the asp.net application, manages and responds to all requests, and all asp.net functions run under the working process. When the request arrives, the worker process generates request and response information.

Application pool:

The application pool is the container of the worker process. It is usually used to separate working processes with different configurations. When a program fails or the process resource is recycled, the programs in other pools are not affected.

Note: When an application pool contains multiple working processes, it is called web garden.

If we look at the structure of iis 6, we will find that it can be divided into two parts:

Kernel model)

User model)

The kernel mode is introduced from iis 6.0, which contains a file called http. sys. When a request arrives, the file response is triggered first.

Http. sys is responsible for transmitting requests to the corresponding application pool. But how does http. sys know which application pool should be passed? Of course it is not random. Every time an application pool is created, the ID of the pool will be generated and stored in http. the sys file is registered, so the file can determine the program pool to which the request is sent.

The above is the first step for IIS to process requests. Next, let's take a look at how requests pass in the application pool from HTTP. SYS.

In the iis user module (user model), requests are received from http. sys through WAS (web admin services) and transferred to the application pool.

When the application pool receives the request, it sends the workflow (w3wp.exe). The process checks the request URL suffix to determine the ISAPI extension to be loaded and then passes the request to the appropriate ISAPI extension.

ASP. NET processes the file extensions mapped to it, such as. aspx,. ascx,. ashx, And. asmx.

That is, when the file is suffixed with the above, the ISAPI extension (aspnet_isapi.dll) of ASP. NET must be loaded)

Once the working process loads aspnet_isapi.dll, an HttpRuntime class (sealed class to prevent derivation) is constructed. This class is the entrance of the application and the HttpContext class is created through the ProcessRequest () method in this class, after entering the ProcessRequest method, a series of internal methods are triggered to create an HttpContext instance (you can use HttpContext. and the instance will be active throughout the lifecycle.

AfterHttpRuntime classForwardHttpApplicationFactory classMake a request 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 the HttpRuntime class. If no, you need to create one for HttpRuntime.

HttpApplicationFactory. _ theApplicationFactory. GetNormalApplicationInstance (context) This method creates an HttpApplication instance and initializes it. Call the System. Web. HttpApplication. InitInternal () method.

When each request arrives, it must pass through the httpModule to reach httphandler for response. Httpmodule is configured in httpApplication.

 

After an HttpApplication instance is created, the InitInternal method of the instance is called.

The main functions of the InitInternal method are as follows:

1. When the HttpAplication object is initialized, call the InitModule method to load all the HttpModule modules configured in the Web. config file.

For example:

<System. web> 

2. The HookEventHandlesForApplicationAndModules method is called to complete the HttpModule orHttpApplication binding.

For example:

  MyModule_ExposedEvent(
   EventHandler ExposedEvent;       +=  EventHandler(context_BeginRequest); context_BeginRequest( EventArgs());  (ExposedEvent !=  

3. Finally, the BuildSteps method of the ApplicationStepManage object is called to bind the HttpApplication event.

4. Execute the events of HttpApplication in sequence. That is, the content of the previously registered HttpModule module that processes or checks requests can also be executed.

Among these events, the 10th events 【Based on the file extension of the requested resource (ing in the application configuration file), select the class that implements IHttpHandler to process the request.]. This event is also created by HttpHandler.

-----------------------------------------------------------------

We have been talking about ASP. NET pipelines before, so,Who is controlling the pipeline process?
The answer is: HttpApplication object.
1. HttpApplication segments its processing process and triggers different events at different stages, so that HttpModule adds events to the request processing process by subscribing to events.
2. In the request processing process, the HttpApplication object is mainly used to control the processing process.
3. HttpApplication obtains an IHttpHandler instance at a fixed stage, and then submits the request response process to the specific IHttpHandler for implementation.

How can I generate and work with HttpApplication?
1. The HttpApplication object will be reused. It will be created only when HttpRuntime cannot obtain idle instances from HttpApplicationFactory.
2. HttpRuntime will send each request to an HttpApplication object for processing.
3. The HttpApplication object is responsible for loading all the httpmodules during initialization.
4. Each HttpApplication object controls its pipeline process.

HttpApplication is a very important type. Many of its functions belong to the basic part of the framework and do not need to be called. Therefore, we usually do not use it.

-------------------------------------------------------------------------

HttpHandler processes requests based on the file extensions (. aspx,. ascx,. ashx, And. asmx) requested by the user.

When an HTTP application sends a request to an HttpHandler instance for processing, it uses an interface to call the ProcessRequest method in a suitable HttpHandler class to process the request.

For example, define a HttpHandler to process the request. (In fact, HttpHandler is a general term for classes that only implement the IHttpHandler interface)

<HttpHandlers> <add path = verb = type =/> 

Therefore, we should understand HttpHanlder as follows:An HttpHanlder is used to respond to a specific type of request.

In the request processing process, the HttpApplication object is mainly used to control the pipeline processing process, and is responsible for promoting the entire processing process, in addition to triggering different events at different stages (for use by HttpModule), The HttpApplication object will also find a suitable IHttpApplicationFactory instance based on the current request, and finally get an IHttpHandler instance to process the request.

When each request arrives, it must pass through the httpModule to reach httphandler for response.Httpmodule is configured in httpApplication.

That is, the process is:

When you request some information on the Web server, the request first reaches Http. SYS, and then Http. SYS sends it to the corresponding application pool. The application pool sends it to the worker process and loads the ISAPI extension. Then, the HttpRuntime object is created and requests are processed through the HttpModule and HttpHandler.

For detailed HttpHandler and HttpModule, you can go to the Fish Li blog:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.