Asp. NET's operation principle and operation mechanism

Source: Internet
Author: User

http://kb.cnblogs.com/page/75702/

When an HTTP request is made to the server and received by IIS, IIS first loads the appropriate. dll file for it through the page type requested by the client, and then sends the request to the module that can handle the request during processing. In ASP. NET 3.5, this module is called the HttpHandler (HTTP handler component), the reason that the. aspx file can be processed by the server is because the server side has a default HttpHandler dedicated to the. aspx file. Before the IIS sends this request to a module capable of handling this request, it also needs some httpmodule processing, which is the system default modules (to get the collection of modules for the current application). The HTTP request passes through a different httpmodule before it is uploaded to HttpHandler. The advantages of this, one is for some necessary process, the second is for security, three is to improve efficiency, four is for users to be able to control more links, enhance the user's control ability. The ASP. NET 3.5 works as shown in principle 1.1.

Figure 1.1 ASP. NET 3.5 Operating principle

Description: The HttpModule module is a component that can be registered as part of the ASP. NET 3.5 request life cycle, which can read or change requests or responses when the component is processed. HttpModule modules are typically used to perform special tasks, such as security or site statistics, that require each request to be monitored.

(PS:

HttpModule Overview:

For the time being, let's not consider our own implementation of the HTTP module. In. NET, the Http Module is an assembly that implements the IHttpModule interface. The IHttpModule interface itself does not have any good capitalization close-up, by its name can be out, it is just an ordinary interface. In fact, what we care about is the class that implements these interfaces, and if we also write code to implement this interface, then what is the use of it? In general, we can divide the events in ASP. Three levels, the topmost is the application-level event, the next is the page-level event, the bottom is the control-level event, the event's triggering is closely related to the application cycle, the page cycle, the control cycle. The role of the Http Module is closely related to application events.

We register a method in the HTTP request pipeline (Pipeline) that expects to react to an application event through the HTTP module, at the time of the corresponding event trigger (for example, the BeginRequest event, It fires when an application receives an HTTP request and is about to process it, invoking the method registered by the HTTP module, and the actual work is performed in these methods.. Net itself already has many HTTP module, including form validation module ( FormsAuthenticationModule), Session status Module (sessionstatemodule), output cache module (OutputCacheModule), and so on.

Learn more: http://www.cnblogs.com/jimmyzhang/archive/2007/11/25/971878.html

The ASP. NET 3.5 runs mechanism 1.2 as shown.

Typically, ASP. NET Framework is built in the Windows Server (Server Edition operating System) +iis (Web server, the English abbreviation for Internet Information Services Manager) environment, when you install the. NET Framework, Setup will register the ISAPI extensions (Aspnet_isapi.dll) required for ASP. NET in IIS, which causes IIS, the ASP. Host, to give control of the response request to the ASP. NET run after receiving the HTTP request from the client.

Asp. NET runtime receives a request, it determines whether the site is accessed for the first time, and if it is the first access, runs the initialization work, such as loading DLL dynamic-link libraries in the bin directory, Read the Web. config Web site configuration file, initialize the HttpApplication instance, compile and load the Global.asax file, etc.). Asp. The NET runtime is also responsible for creating a HttpContext context instance of the request response thread and creating a Httptextwriter instance that hosts the response result. Then, ASP. The net runtime is looking for the appropriate HttpHandler (usually the ASP) to process the HTTP request and wait for HttpHandler to return the request processing results. Finally, ASP. NET runtime after completing some follow-up work, such as saving session, exception handling, and then returning the response structure to the client through IIS.

Figure 1.2 ASP. NET 3.5 operation mechanism

Note: The primary task of the ASP. NET ISAPI work is to schedule aspnet_wp.exe to process requests and monitor the execution of the aspnet_ WP.exe process, and if the Aspnet_wp.exe process cannot complete the task, the ASP. The ISAPI arranges a new aspnet_wp.exe to handle the work. The main task of Aspnet_wp.exe is to give the request to a series of managed objects called the HTTP pipeline. If the ASP is a vendor, then aspnet_wp.exe is the manufacturer, and the HTTP pipeline is the production line, the team responsible for the pipeline is httpruntime. Producer Aspnet_wp.exe will hand over the order (HTTP request) to httpruntime Team staff ProcessRequest (HttpWorkerRequest wr), httpruntime according to the internal division of labor, It is eventually produced by ProcessRequestInternal (HttpWorkerRequest WR) on the assembly line.

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.