Understanding and deepening understanding of httpruntime

Source: Internet
Author: User
Keywords Nbsp; http dler fact

The following is the first introduction to HttpRuntime's Web.config configuration

<httpruntime


executiontimeout = "number"


maxRequestLength = "number"


Requestlengthdiskthreshold = "number"


useFullyQualifiedRedirectUrl = "[true| False] "


minFreeThreads = "number"


minLocalRequestFreeThreads = "number"


appRequestQueueLimit = "number"


Enablekerneloutputcache = "[true| False] "


enableversionheader = "[true| False] "


apartmentthreading = "[true| False] "


requireRootedSaveAsPath = "[true| False] "


Enable = "[true| False] "


sendcachecontrolheader = "[true| False] "


shutdowntimeout = "number"


delaynotificationtimeout = "number"


waitchangenotification = "number"


maxwaitchangenotification = "number"


enableheaderchecking = "[true| False] "


/>

With the configuration instructions above, the following is the setting of the node in Web.config

<configuration>


<system.web>


<httpruntime maxrequestlength= "4000"


enable = "True"


requestlengthdiskthreshold= "512


usefullyqualifiedredirecturl= "True"


Executiontimeout= "45"


versionheader= "1.1.4128"/>


system.web>


configuration>

Every request that IIS receives for a Microsoft asp.net page is handed over to the ASP.net HTTP pipeline. The HTTP pipeline consists of a series of managed objects that process the request sequentially and complete the conversion from the URL to the normal HTML text. The entry point for the HTTP pipeline is the HttpRuntime class. ASP.net infrastructure Create an instance of this class for each AppDomain hosted in the worker process note that the worker process maintains a different AppDomain for each ASP.net application that is currently running.

To activate an HTTP pipe, you can create a new instance of the HttpRuntime class and then call its ProcessRequest method. A complete page request includes the following process:
First intercepted by the WWW server (Inetinfo.exe process), the process first determines the page suffix, and then invokes the specific extender based on the configuration decision in IIS. ASPX invokes Aspnet_isapi.dll,
The aspnet_isapi.dll is then sent to W3wp.exe (the IIS worker process, IIS6.0 called aspnet_wp.exe in w3wq.exe,iis5.0).

Next, call the. NET class library in w3wp.exe for specific processing, in the following order: Isapiruntim, HttpRuntime, HttpApplicationFactory, HttpApplication, HttpModule, Httphandlerfactory, HttpHandler

Isapiruntime: The main role is to invoke some unmanaged code to generate the HttpWorkerRequest object, HttpWorkerRequest the object contains all the information of the current request, and then pass it to the httpruntime
HttpRuntime: Httpcontext,httpcontext includes request, response, etc. based on HttpWorkerRequest object generation. Call HttpApplicationFactory to generate IHttpHandler, invoke the HttpApplication object to execute the request
HttpApplicationFactory: Generate a HttpApplication object
HttpApplication: Initialize HttpModule, HttpApplication create HttpContext object for this HTTP request
HttpModule: When an HTTP request arrives at HttpModule, the entire ASP.net framework system does not do anything with the HTTP request, which means that at this point HttpModule is an HTTP request for HTTP requests "Only Way", so you can append the required information to the HTTP request information before the HTTP request is passed to the Real Request Processing Center (HttpHandler), or do some extra work on the intercepted HTTP request information. Or, in some cases, simply terminate the HTTP request that satisfies some of the conditions so that it can act as a filter.
Httphandlerfactory: Forward user request to Httphandlerfactory, and then httphandlerfactory instantiate HttpHandler object to request
Httphandle:http handler, processing page request

See from the above httpruntime one of the ProcessRequest methods
public static void ProcessRequest (HttpWorkerRequest wr); Drives all asp.net Web processing execution. Pseudocode is as follows:

public static void Httpruntime.processrequest (HttpWorkerRequest wr)


 {


//Checks whether the current caller has permission to act as a ASP.net host (host)


InternalSecurityPermissions.AspNetHostingPermissionLevelMedium.Demand ();





if (WR = null)


   {


throw new ArgumentNullException ("Custom");


   }





requestqueue queue = Httpruntime._theruntime._requestqueue;





if (queue!= null)


   {


//The Web page request in the parameter is placed in the request queue and a page request is fetched from the queue using the FIFO policy


WR = queue. Getrequesttoexecute (WR);


   }





if (WR!= null)


   {     


Httpruntime.calculatewaittimeandupdateperfcounter (WR); Update performance Counters


Httpruntime.processrequestnow (WR); Actually complete the page request work


   }


 }


The Processrequestnow function then calls the ProcessRequestInternal function of the default httpruntime instance to complete the actual page request, pseudocode as follows:

internal static void Httpruntime.processrequestnow (HttpWorkerRequest wr)


{


httpruntime._theruntime.processrequestinternal (WR);


}

The ProcessRequestInternal function logic is slightly more complex and can be roughly divided into four parts:
Checks whether the current httpruntime instance is invoked for the first time, and initializes it with the Firstrequestinit function if it is the first call.
Call the Httpresponse.initresponsewriter function to initialize the return object of the page request Httpworkerrequest.response
Call the Httpapplicationfactory.getapplicationinstance function to get the current Web application instance
Complete the actual page request work using a Web application instance
Pseudocode is as follows:

Code


private void Httpruntime.processrequestinternal (HttpWorkerRequest wr)


 {


//Constructed HTTP call context object


HttpContext ctxt = new HttpContext (WR, 0);





//Set send end asynchronous callback function


WR. Setendofsendnotification (This._asyncendofsendcallback, ctxt);





//Update request counter


interlocked.increment (& (This._activerequestcount));





Try


{


//Check whether the current httpruntime instance is invoked for the first time


if (this._beforefirstrequest)


     {


Lock (This)


       {


//Use double-checked mode to avoid redundant locking


if (this._beforefirstrequest)


         {


this._firstrequeststarttime = Datetime.utcnow;


this. Firstrequestinit (Ctxt); Initializes the current HttpRuntime runtime environment


This._beforefirstrequest = false;


         }


       }


     }





///According to profile settings, play a higher privileged role


Ctxt. Impersonation.start (True, false);


Try


     {


//Initialization of the return object for the page request


Ctxt. Response.initresponsewriter ();


     }


finally


     {


Ctxt. Impersonation.stop ();


}





//Get the current Web application instance


IHttpHandler handler = httpapplicationfactory.getapplicationinstance (Ctxt);





if (handler = null)


     {


throw New HttpException (httpruntime.formatresourcestring ("Unable_create_app_object"));


     }





//Use the Web application instance to complete the actual page request work


if ((handler as IHttpAsyncHandler)!= null)


     {


IHttpAsyncHandler Asynchandler = ((IHttpAsyncHandler) handler);


Ctxt. Asyncapphandler = Asynchandler;


//using asynchronous processing mechanism


asynchandler.beginprocessrequest (Ctxt, This._handlercompletioncallback, ctxt);


     }


Else


     {


handler. ProcessRequest (Ctxt);


this. Finishrequest (Ctxt. Workerrequest, ctxt, NULL);


     }


   }


catch (Exception E)


   {


Ctxt. Response.initresponsewriter ();


This. Finishrequest (WR, Ctxt, E);


   }


 }

The Httpapplicationfactory.getapplicationinstance function is called in the httpruntime.processrequestinternal function to get the current Web application instance. At least httpruntime is finished and will be transferred to the httpapplicationfactory phase process. As you can see, the function around httpruntime has a httpworkerrequest parameter, and the following is a brief introduction to the function of this parameter. In the isapiruntime phase, some unmanaged code is invoked to generate the HttpWorkerRequest object that contains all the information for the current request and then passes to httpruntime. The HttpWorkerRequest object generated here can be invoked directly on our page.
IServiceProvider provider= (IServiceProvider) httpcontext.current;
HttpWorkerRequest wr= (HttpWorkerRequest) provider. GetService (typeof (HttpWorkerRequest));
You can then invoke the method inside by WR. The method contained in the HttpWorkerRequest class can be seen from its metadata, as follows:

Code


public abstract class HttpWorkerRequest


    {


//Abstract:


Specifies the index number for the accepthttp header.


Public const int headeraccept = 20;


        //


//Abstract:


//Specifies the index number of the accept-charsethttp header.


Public const int headeracceptcharset = 21;


        //


//Abstract:


//Specifies the index number of the accept-encodinghttp header.


public const int headeracceptencoding = 22;


        //


//Abstract:


//Specifies the index number of the accept-languagehttp header.


Public const int headeracceptlanguage = 23;


        //


//Abstract:


//Specifies the index number of the accept-rangeshttp header.


Public const int headeracceptranges = 20;


//


//Abstract:


//Specifies the index number of the agehttp header.


Public const int headerage = 21;


        //


//Abstract:


//Specifies the index number of the allowhttp header.


Public const int headerallow = 10;


        //

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.