Asp. NET bottom architecture explore again. NET Runtime (ii)

Source: Internet
Author: User
Tags abstract object cgi web int size interface net reference thread
Here we have an instance of the callable Isapiruntime object that is active in the ISAPI extension. Each time the runtime is started and running (in contrast, if the runtime does not start, you need to load the runtime as described in the previous chapter), the ISAPI code calls the Isapiruntime.processrequest () method, This method is really the entry into the ASP.net pipeline, which is shown in Figure 4.

Remember that the ISAPI is multi-threaded, so the request will also pass Appdomainfactory.create () (the original applicationdomainfactory, suspect) The reference returned in the function is processed in a multithreaded environment. Listing 1 shows the Isapiruntime.processrequest code in the method () that receives an ISAPI ECB object and service type (Workerrequesttype) As a parameter. This method is thread-safe, so multiple ISAPI threads can call this method safely on this returned object instance at the same time.

The list 1:processrequest method receives an ISAPI ECB and passes it to the worker thread

public int ProcessRequest (IntPtr ECB, int iwrtype)
{
HttpWorkerRequest request1 = isapiworkerrequest.createworkerrequest (ECB, iwrtype);
String Text1 = Request1. Getapppathtranslated ();
String text2 = httpruntime.appdomainapppathinternal;
if ((Text2 = null) | | Text1. Equals (".")) ||
(String.Compare (Text1, Text2, true, cultureinfo.invariantculture) = = 0))
{
Httpruntime.processrequest (REQUEST1);
return 0;
}
Httpruntime.shutdownappdomain ("Physical application path changed from" +text2 + "to" + Text1);
return 1;
}


The actual code here is not important, remember that this is from the internal framework code decompile, you can not directly deal with it, It is also likely to change in the future. It's just used to reveal what's going on behind the scenes. The ProcessRequest method receives an unmanaged ECB reference and passes it to the Isapiworkerrequest object. This object is responsible for creating the creation request context for the current request. This procedure is shown in Listing 2.

The System.Web.Hosting.ISAPIWorkerRequest class is an abstract subclass of the HttpWorkerRequest class (HttpWorkerRequest and Isapiworkerrequest are abstract classes, And Isapiworkerrequest inherits from HttpWorkerRequest), its job is to build an abstract perspective of input and output as input to Web applications. Note that there is another factory method: Createworkerrequest, to create the corresponding Workerrequest object by judging the second parameter that is accepted. There are three different versions: Isapiworkerrequestinproc, ISAPIWorkerRequestInProcForIIS6, Isapiworkerrequestoutofproc. Each time a request enters, the object is created and serves as the basis for the request and response object, which receives their data and the stream of data provided by Workerrequest.

The abstract HttpWorkerRequest class provides a high-level abstraction on the low-level interface, which encapsulates where the data comes from, can be a CGI Web server, a Web browser control, or something you use to "feed" the HTTP runtime. The mechanism for customizing the data. The key is that ASP.net can receive information in a uniform way.

in the case of IIS, this abstraction is built around the ISAPI ECB block. During our request processing, Isapiworkerrequest hangs the ISAPI ECB and takes out information from it as needed. Listing 2 shows the request string value (query How string value is taken out.

Listing 2: The Isapiworkerrequest method for using unmanaged data

//* * implemented in Isapiworkerrequest

{
byte[] buffer1 = new Byte[this._querystringlength];
if ( This._querystringlength > 0
{
int num1 = this. Getquerystringrawbytescore (Buffer1, this._querystringlength);  
if (num1!= 1)
{
throw new HttpException ("Cannot_get_query_string_bytes");

}
return Buffer1
}
//* * implemented in a specific implementation class ISAPIWorkerRequestInProcIIS6

internal override int getquerystringcore (int encode,stringbuilder buffer, int size)
{
if ( THIS._ECB = = IntPtr.Zero)
{
return 0;
}
return unsafenativemethods.ecbgetquerystring (this._ecb,encode,buffer,size);
}

 

Isapiworkerrequest implements a high-level packaging approach that calls the low-level core approach, which is responsible for real access to unmanaged apis-or "service level implementations" (services levels implementation). These core methods provide a special implementation for the environment in which it is hosted in a special Isapiworkerrequest subclass, which implements a simple extended (pluggable) environment, This allows additional implementation classes to be provided simply when the new Web server interface or other platform becomes the target of the asp.net. There is also an assistance Class (helper Class) System.Web.UnsafeNativeMethods. Many of the operations on the ISAPI ECB structure implement unmanaged operations to the ISAPI extension.



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.