ASP. NET pipeline Model (pipeline model)

Source: Internet
Author: User
Tags httpcontext metabase

Objective

Why do I have such a title, in fact, I originally only want to understand the pipeline model of ASP, but in the view of the data encountered in the non-understanding of the place and looked at the other relevant information, and the harvest is much larger than originally expected.

With this article as the basis, the following two articles are better understood:

Understand and customize HttpHandler

Understand and customize HttpModule

Directory

Generally do not write a directory, feel this time to write something more write a clear it.

1.asp.net pipeline model;

2. The process's child process and the thread of the process;

3. Application domain (AppDomain);

4.iis5.x The overall framework for the next HTTP request/Response process

The difference between 5.iis5.x, iis6.x and iis7.x

ASP. NET pipeline Model

Reference: ASP. NET uses pipeline model (Piplelines) to process HTTP requests

Understanding and deepening understanding of httpruntime

HttpModule's Knowledge (reproduced)

The pipeline model contains the following objects:

Flow chart:

Http request is uploaded to the worker process (iis5.x is aspnet_ Wp.exe,iis6.x and iis7.x are w3wp.exe), the worker process instance is isapiruntime through (the main function is to invoke some unmanaged code to generate the HttpWorkerRequest object, and the HttpWorkerRequest object contains all the information for the current request. Then passed to httpruntime) passing the HttpWorkerRequest object to httpruntime and calling HttpRuntime's ProcessRequest method, HttpRuntime is the inlet of the piping model at this time formally into the piping model.

  HttpRuntime generates Httpcontext,httpcontext based on the HttpWorkerRequest object containing the request, response, and other attributes. Then call HttpApplicationFactory's GetApplicationInstance method to generate the HttpApplication, The HttpApplication object contains multiple HttpModule objects (when an HTTP request arrives at HttpModule, the entire ASP. NET Framework system does not do any processing of this HTTP request. In other words, for an HTTP request, HttpModule is a "must-have" for an HTTP request, so you can append some required information to the HTTP request before the HTTP request is passed to the Real Request Processing Center (HttpHandler). Or for the interception of this HTTP request information to do some extra work, or in some cases simply terminate the HTTP request to meet some conditions, so as to play a role of filter filters), The Init method of each HttpModule object is called to initialize the HttpModule, and the Init method can subscribe to the HttpApplication event to make the corresponding processing. When HttpApplication executes to Application_ Resolverequestcache temporarily gives control to HttpHandler and determines whether the session tracing feature is generated (in. aspx with EnableSessionState settings, in. ashx, based on whether sessionstate is enabled in the HttpHandler). Inherit the IRequiresSessionState interface to set up), The HttpApplication then proceeds to execute its own event until the PreRequestHandlerExecute event is executed and gets the Httphandlerfactory object based on the suffix name of the URL request (by default. aspx calls System.Web.UI.Pag Ehandlerfactory,. ASHX call System.Web.UI.SimpleHandlerFactory), call Httphandlerfactory's GetHandler method to generate a specific HttpHandler object or invoke the Releasehandler method so that the factory can reuse the existing Handler instance to process an HTTP request and return an HTTP response, passing through a series of events of the HttpApplication object(For specific events, refer to HttpModule's understanding (reprint)) eventually return to the client, of course, the HTTP response of the HttpApplication series of events can be subscribed to HttpModule objects.

The process's child process and the thread of the process

Reference: Baidu Quiz

I take windows for example, because the Linux kernel seems to have no threading concept. The difference between a process and a thread is that the granularity is different, and the variables (or memory) between processes are not directly accessible to each other, and threads are bound to execute on a process. Let me give you an example You open an IE browser under Windows, this IE browser is a process. You use the browser to open a PDF, IE will go to call Acrobat to open, then Acrobat is a separate process, IE is the child process. and IE itself in the same process with a 2 Web page, and at the same time running two pages on the script, The implementation of these two Web pages is IE itself through two threads. It is worth noting that the thread is still the content of IE, and the subprocess is strictly not part of IE, it is another program. The reason is the child process of IE, only by IE call to start.

Ask: That I can understand, the parent process created a child process, as long as the sub-process assigned a certain task, they have no relationship from now on ....

Answer: It's okay to say that. The parent process can still get some information by communicating with the child process. Take the example above,

IE can use the interface of some interprocess communication to know if Acrobat has successfully opened the PDF. But one thing I think you understand is basically right,

Is that the parent and child processes are independent. If IE opened a virus sub-process, the child process is not obedient, the parent process is nothing special, except to apply to the system to close it.

Zone molecular processes and threads are simple: the run of a standalone program is called a process, and the different parts of the process executing concurrently are called threads. Additional standalone programs that are thrown by this process run as child processes of this process.
(Basically, the more rigorous definition suggests reference to the operating system of the textbook)
  Reference:. NET simple talk about component programming (AppDomain application domain)
  Reference: http://blog.csdn.net/zhoufoxcn/article/details/2425420 in the reply of Zhou Gong
  Process: belongs to the concept of the operating system, a process occupies a memory address, is the boundary between the application and the application, the process can not share code and data space (that is, cannot directly interact), but through the IPC (remoting, named pipe, WebService, etc.) for data interaction. A process error or even a crash does not affect the execution of other processes.
  Child process: Initiated by another process, the child process has no affiliation with the parent process, and the two processes can interact with the data through the IPC.
  Threads: Concepts that are part of the operating system, are the boundaries of the code execution stack and the execution context, and multiple threads of the same process share code and data space, but are only responsible for executing the code without the ability to carry the data. Independent or multiple threads are responsible for executing the tasks in the process.
  Outside: There are a lot of things you can do about threading, more on threading
application domain (AppDomain)
Reference: Understanding AppDomain
  The AppDomain is a unique concept of the. NET Framework, a logical host that functions like a process as a separate space for a program to run (allocating independent memory space from a process, and the AppDomain cannot share code and data space). Programs that run in other AppDomain are not affected when a program in an AppDomain is abnormally or even crashes. But the AppDomain is not a process, and a process can have one or more AppDomain, which must have a default AppDomain.
  Perhaps you have this question here: is the AppDomain a thread? What if it's not so related to threading? There are processes, application domains (AppDomain), threads three independent and connected concepts in the. NET Framework, one process with one or more AppDomain (a default AppDomain must exist) A process with one or more threads (usually containing a thread pool with multiple reusable threads); The AppDomain is a many-to-many relationship with a thread, but a thread can handle only one appdomain at a time, and the AppDomain can be processed concurrently by multiple threads.
  The process from running the program is this: the system first allocates a memory address space and then gives control to the CLR to generate the default AppDomain, and then loads the assembly into the default AppDomain, which is formally run (the system does not have the concept of an AppDomain in the managed heap, The AppDomain is not the concept of an operating system, managed by the CLR. The default AppDomain is born with the CLR and cannot be encoded to delete or unload an assembly.
  The position of the process, thread, and AppDomain is described in the following diagram.

There is no direct interaction between the AppDomain and the data can be interacted by proxy (if the process uses IPC). (Concrete implementation after the discussion!) )

iis5.x The overall framework for the next HTTP request/Response process

  

On the left is iis5.x WEB SERVER, and the worker process for ASP. NET application on the right, which extends IIS as an IIS component.

Reference: Different versions of IIS under the ASP. NET Request Processing process

When an HTTP request is sent to iis5.x, IIS first turns the virtual directory into a physical directory, and then checks the metabase file in IIS based on the file suffix name to check the file extension and executable code (extender) mapping records such as. aspx,. ASHX, such as Aspnet_isapi.dll), if the metabase file does not check whether it is not server-side protected files (server-side protection: Files under the App_Code folder, not server-side protection: CSS, JS files), Returns the 404HTTP status code directly to the client if none exists, and the Inetinfo.exe instance of IIS invokes the corresponding executable code (this is a lookup that can be passed through "understanding and Customizing HttpHandler") (This is the aspnet_ Isapi.dll), Aspnet_isapi.dll will pass a named pipe (named pipe, a simple ipc--process communication mechanism, please refer to the following: "Named pipe and extended process communication learning" Asynchronously forwards the request fetched from Inetinfo.exe to the ASP. NET worker Process instance: aspnet_wp.exe, then enters the pipeline model. At the same time aspnet_isapi.dll through the named pipe monitoring the health of the work process, if the performance of the work process is lower than a certain value aspnet_isapi.exe will kill the worker process, when the next request passed over a worker process to restart processing requests. The worker process synchronously requests the Web server information (such as invoking the server object to obtain information about the servers) through named pipe.

Figure still adhering to my ugly but very useful principle, hehe!!
 aspnet_ Wp.exe's work process contains a thread pool and a default AppDomain, and when a request is sent to a worker process, the worker process creates the AppDomain from the default AppDomain based on the file of the requested virtual directory (a virtual directory corresponds to a application) and adds the virtual The Assembly of the directory is loaded into the AppDomain (there may be more than one assembly in the virtual directory, and the default AppDomain loads all the assemblies under the entire virtual directory into the AppDomain). If the AppDomain for that virtual directory already exists, use the AppDomain directly, If the virtual directory's assembly changes (including the Web. config change), a new AppDomain is created to load the changing assembly into the new AppDomain, and the thread pool gets the idle thread execution assembly (writing a Web site published as two virtual directories for testing, you can see that the HTTP request is executed at Two virtual directories will appear to use the same thread). The variables and states in the assembly are stored in the memory of the AppDomain in which they belong, such as HttpContext.Current.Items, application, etc. (Application object is actually a hashtable, Can be used by multiple threads (IIS5. X) or multiple application instances (iis6.x), the AppDomain cannot directly access each other's variables and states. There are three modes of session state variables InProc, stateserver, and SQL Server, The default is InProc, which means that session state is saved in the ASP. If the virtual directory's assembly changes and the session state variable set before the new AppDomain is called, the session is lost (the SessionID stored in the client's cookie Old, if the presence should be readable), indicating that session mode is INPROC when the session state variable is stored in the corresponding AppDomain. 
Aside: If the session mode is set to StateServer to use the state server to save the session state, it is to use another local or remote process to save the session state, and to open the state server step locally (the system is windows Server type): 1. Start the ASP. NET Status service, services, administrative Tools, all programs, and then configure the Web. config for <sessionstate mode= " StateServer "stateconnectionstring=" tcpip=localhost:4242 "/>
The difference between iis5.x, iis6.x and iis7.x
Reference: Different versions of IIS under the ASP. NET Request Processing process
Iis5.x is designed to enable only one worker process per server to handle all requests/responses, to ensure that each application (in a virtual directory) runs independently and without interfering with other application (a application crash does not cause the entire process to crash). The AppDomain was introduced. But the AppDomain did not work well, so iis6.x started using the application pool (application pool). In a non-Web garden mode, a application corresponds to an application pool, corresponding to a worker process, 6.x starts the working process from aspnet_wp to w3wp; in Web garden mode A application corresponds to an application pool, For multiple worker processes, application can be executed on any worker process, and once one of the worker processes crashes, the application request can be processed in a timely manner, but sessionstate cannot use InProc mode in Web garden mode. Because this mode saves sessionstate in the AppDomain of the worker process.
The iis5.x identifies which application is implemented in user mode in the worker process, and iis6.x is implemented in core mode by HTTP. SYS of the Web server (iis5.x aspnet_ Isapi.dll, and iis6.x started using the new component, HTTP. sys). Note: To avoid user applications accessing or modifying critical operating system data, Windows provides two processor access modes: User mode and kernel mode (Kernel modes). In general, the user program runs under User mode, while the operating system code runs under kernel mode. Kernel Mode's code allows access to all system memory and all CPU instructions.
The iis5.x and iis6.x are all in IIS ISAPI extension with IIS, and iis7.x begins to inherit ASP into IIS, and the iis7.x work mode has both Classic mode and integrated mode, see reference for details.
This article is Source Oh! http://www.cnblogs.com/fsjohnhuang/archive/2012/07/12/2587658.html

ASP. NET pipeline Model (pipeline model)

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.