Understanding ASP. NET underlying architecture (4)

Source: Internet
Author: User
Tags reflector
Enter . Net Runtime

Enter. net runtime real portals occur in some classes and interfaces not documented (translated: Of course, you can use reflector to view J ). few people except Microsoft know these interfaces, and Microsoft do not like to talk about these details. They think these Implementation Details are applicable to the use of ASP. NET developers are useless.

Working Process (aspnet_wp.exe in iis5 and w3wp in IIS6. EXE) host. net runtime and isapi dll, which sends the call to an instance of the isapiruntime class by calling a small unmanaged interface of the COM Object: the original article is an instance subclass of the isapiruntime class, but the isapiruntime class is a sealed class, which may be written incorrectly by the author, or the subclass here does not mean a subclass ). the first entry to the runtime is the class not documented. This class implements the iisapiruntime interface (for the caller's description, this interface is a COM interface) the underlying COM interface based on iunknown is extended from ISAPI to ASP.. net. figure 3 shows the iisapiruntime interface and its call signature. (Lutz roeder is used. net reflector tool http://www.aisto.com/roeder/dotnet ). this is a good way to explore this step-by-step process.


Figure
3-If you want to go deep into this interface,OpenReflector,PointSystem. Web. HostingNamespace. ISAPI DLLBy calling a managedComInterface to openASP. NETPortal, ASP. NETReceive a pointISAPI ECBUnmanaged pointer.ThisECBIncluding complete accessISAPIInterface capabilities,Used to receive requests and send responsesIIS.

The iisapiruntime interface serves as the unmanaged code extended from the ISAPI and ASP.. Net interfaces (IIS6 directly connects, iis5 uses the named pipeline ). if you look at the interior of this class, you will find the processrequest function containing the following signature:

[Return: financialas (unmanagedtype. I4)]
Int processrequest ([in] intptr ECB,
[IN, financialas (unmanagedtype. I4)] int useprocessmodel );

The ECB parameter is the extention control block of ISAPI, which is passed to the processrequest function as an unmanaged resource. after receiving the ECB, this function serves as the basic input and output interface and is used with the request and response objects. the isapi ecb contains all the underlying request information, such as server variables. It is used for the input stream of form variables and the output stream for data writeback to the client. this ECB reference basically provides all the functions used to access resources that can be accessed by ISAPI requests. processrequest is the resource (ECB) that was initially exposed to the ingress and exit of managed code.

ISAPI extensions process requests asynchronously. in this mode, the ISAPI extension will immediately return the call to the working process or IIS thread, but the ECB will remain available in the lifecycle of the current request. ECB contains a mechanism for ISAPI to know that the request has been processed (through ECB. serversupportfunction (for more information, refer to the article on developing ISAPI extensions), which releases the ECB. this asynchronous processing method can immediately release the ISAPI working thread and pass the processing to the ASP.. Net management on a separate thread.

ASP. net receives references from the ECB and uses it internally to receive information about the current request, such as server variables and post data. It also returns information to the server. ECB maintains accessible (stay alive) before the request is completed or before the timeout period ends, so that ASP. net can continue to communicate with it until the request processing is complete. the output is written to the ISAPI output stream (using ECB. writeclient () and the request is completed. The ISAPI extension is notified of the request processing completion and the ECB is released. this implementation is very efficient, because. net class is essentially a very "thin" (thin) wrapper for the efficient and unmanaged isapi ecb.

Load. Net-A little mysterious

Let's go back from here: I skipped it. net Runtime is loaded. this is a bit vague. I did not find any documentation in this process, and there is no good way to decompile the ISAPI DLL and find it (load. net runtime code.

The best guess I can make is when the ISAPI extension receives the first ASP ing to ASP. net extension request, the worker process is loaded. net runtime. once running, the unmanaged code can request an isapiruntime instance for the specified virtual directory (if the instance does not exist ). each virtual directory has its own application domain (appdomain). When an Independent Application (an ASP. the isapiruntime exists in the application domain from the startup process. instantiation seems to be implemented through COM, because interface methods are exposed as callable methods of COM.

When the first request for a virtual directory arrives, system. web. hosting. appdomainfactory. the create () function is called to create an isapiruntime instance. this starts the Startup Process of the application. this call receives the type, Module name, and virtual directory information of the application, which is ASP. net is used to create an application domain and start ASP. net program. this httpruntime instance is created in a new application domain. each virtual directory (that is, an ASP.. NET application. net program will be loaded only when it is requested. ISAPI extends the management of these httpruntime object instances, and routes internal requests to the correct httpruntime object based on the virtual directory of the request.


Figure
4-isapiRequest to use classes not documented,Interface and call many factory methods to sendASP. NETOfHTTPMPs queue Process.EachWebProgram/The virtual directory runs in its own application domain,Caller(Annotation:RefersIsapi dll)Keep oneIisapiruntimeAPI reference to triggerASP. NETRequest Processing.

 

Related Article

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.