The process of object generation and httphandler and httpmodule during ASP. NET runtime.

Source: Internet
Author: User

Now we will describe the final process. What happens when Asp.net obtains An ASPX system request in the ISAPI of IIS and obtains control.

If not, create one and transfer the control to the process (that is, the function pointer jump operation ).

When the process is under control, check whether there is an httpruntime class instance in the application domain set by the application program of the site in the process. If no instance is created, create a new instance. A server can have multiple httpruntime instances, because the IIS of a server may create multiple sites, and each site may create multiple virtual directories. However, each site can only create a new httpruntime instance to avoid occupying too many system resources.

Httpruntime is the basis of the Asp.net Runtime Library Program. He is responsible for controlling Asp.net requests for each site/virtual directory (not HTTP requests), but is not responsible for processing requests. The httruntime object controls the httpapplicationfactory object, which is a class factory object and is responsible for generating classes.

The httpapplicationfactory class controls an object pool. The objects in the object pool are commonly used httpapplication objects.
Httpapplicationfactory processes the global. ascx program, triggers the application_onstart event, obtains an httpapplication instance from the pool, and puts the requests to be processed into the instance. If no available object exists, a new httpapplication object is created. To create an httpapplication object, you must first compile the global. asax application file. Then, httpapplication starts to process the request and can only process the new request after the request is completed. If a new request from the same resource is received, other objects in the pool are processed. That is to say, if a site has many users, therefore, multiple requests of multiple users are processed by different httpapplications.

The application object allows all registered HTTP modules to pre-process requests (note that httpmodule is starting to work) and find the processing program type that is most suitable for processing requests. This is done by finding the extension of the requested URL and the information in the configuration file.

Therefore, the final processing of the Asp.net page is a class instance named httpapplication. According to the above steps, we can conclude that when httpruntime starts httpapplicationfactory, the first thing we start is Asp.net's event Preprocessing Program global. ascx, and then it is the turn of httpapplication.

How does the aspx processing definition system know? The answer is obtained from the machie. config configuration file. This file defines all the. aspx,. ashx,. asmx,. ascx and other file handlers.

Conclusion: The processing process ISAPI --> aspnet_wp.exe/w3wp.exe --> httpruntime --> httpapplicationfactory --> httpapplication --> content html

Can we customize process processing? Yes. The method is to paste the httpmodule (HTTP module) and httphandle (HTTP processor) of the main question.

Httpmodule is the global run by httpapplicationfactory before httpapplication processing. the custom version of The ascx event handler. It allows you to write a class that inherits the ihttpmodule interface instead of Asp.net to process a certain ASPX page or even all aspx pages, instead, Asp.net can help you deal with it.
And httphandler is global. after being processed by ascx, you can write a class that inherits ihttphandler to replace httpapplication to process a certain aspx or all Aspx, you can handle any content of aspx as you like. However, it is very convenient to write code to process all the content.

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.