Introduction to ASP. NET Applications

Source: Internet
Author: User
Tags reflector

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.

 
 
  1. protected void Application_BeginRequest(Object sender, EventArgs e)  
  2. {  
  3. //*** Request Logging  
  4. if (App.Configuration.LogWebRequests)  
  5. Context.Items.Add("WebLog_StartTime",DateTime.Now);  
  6. }  
  7.  
  8. protected void Application_EndRequest(Object sender, EventArgs e)  
  9. {  
  10. // *** Request Logging  
  11. if (App.Configuration.LogWebRequests)  
  12. {  
  13. try  
  14. {  
  15. TimeSpan Span = DateTime.Now.Subtract( (DateTime) Context.Items["WebLog_StartTime"] );  
  16. int MiliSecs = Span.TotalMilliseconds;  
  17. // do your logging  
  18. WebRequestLog.Log(App.Configuration.ConnectionString,true,MilliSecs);  
  19. }  
  20. }  


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 ).

  1. HttpWorkerRequest object in ASP. NET
  2. Details about four ASP. NET statuses
  3. ScriptManager control in ASP. NET AJAX
  4. SuperPreview calls ASP. NET or PHP to render the webpage
  5. ScriptManager control in ASP. NET

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.