When a request arrives, it is routed to ISAPIRuntime. processRequest () method. this method calls HttpRuntime. processRequest method, which performs some important tasks (use Reflector to view the System. web. httpRuntime. processRequestInternal method ):
◆ Create a new HttpContext instance for the request
◆ Get an HttpApplication instance
◆ Call HttpApplication. Init () to set MPs queue events
◆ The Init () method triggers the HttpApplication. ResumeProcessing () method that starts ASP. NET pipeline processing.
Introduction to ASP. NET application. First, a new HttpContext object is created and used to pass the ISAPIWorkerRequest (the wrapper of the isapi ecb ). this context is always available throughout the request lifecycle and can always be accessed through the static attribute HttpContext. currect to access. as the name implies, the HttpContext object represents the context of the current active Request because it contains all the typical important objects you need to access in the Request lifecycle: Request, Response, application, Server, Cache. httpContext. current gives you access to all these capabilities.
The HttpContext object also contains a very useful Items set. You can use it to save data for specific requests. the context object is created at the beginning of the Request cycle and released at the end of the request. All data stored in the Items set is only available in this specific request. A good example is the request log mechanism. the Application_BeginRequest and Application_EndRequest Methods attached to asax record the request start and end times (as shown in figure 3 ). httpContext is very useful to you-if you need data in different parts of the request or page processing, you can use it freely.
- protected void Application_BeginRequest(Object sender, EventArgs e)
- {
- //*** Request Logging
- if (App.Configuration.LogWebRequests)
- Context.Items.Add("WebLog_StartTime",DateTime.Now);
- }
-
- protected void Application_EndRequest(Object sender, EventArgs e)
- {
- // *** Request Logging
- if (App.Configuration.LogWebRequests)
- {
- try
- {
- TimeSpan Span = DateTime.Now.Subtract( (DateTime) Context.Items["WebLog_StartTime"] );
- int MiliSecs = Span.TotalMilliseconds;
- // do your logging
- WebRequestLog.Log(App.Configuration.ConnectionString,true,MilliSecs);
- }
- }
- }
Once the context is set, ASP. NET needs to route the received requests to the appropriate application/virtual directory through the HttpApplication object. each ASP.. NET Applications must be set to a virtual directory (or Web root directory), and each "application" is processed separately.
HttpApplication is similar to the host of the ceremony-it is the place where the processing action begins.
Domain Master: HttpApplication
Each request is routed to an HttpApplication object. the HttpApplicationFactory class serves your ASP.. NET application creates an HttpApplication Object pool and distributes references to the HttpApplication object for each request. the size of the Object pool is affected by machine. the MaxWorkerThreads setting limit in the ProcessModel key in the config file. The default value is 20. This may be incorrect. According to the code decompiled by Reflector, the pool size should be 100, if the pool size is less than 100, HttpApplicationFactory will create 100 full tables, but considering that multiple threads will create HttpApplication at the same time, the actual size may exceed 100 ).
- HttpWorkerRequest object in ASP. NET
- Details about four ASP. NET statuses
- ScriptManager control in ASP. NET AJAX
- SuperPreview calls ASP. NET or PHP to render the webpage
- ScriptManager control in ASP. NET