Asp. NET mechanism for detailed pipeline event flow

Source: Internet
Author: User
Tags httpcontext

Recently reviewed some new knowledge, I briefly introduce the next ASP. NET mechanism: here to share with you:

First. The browser sends a request to the server.

1) The browser sends the domain name of the requested URL to the IIS server, encapsulates the request message according to the HTTP protocol, resolves the requested IP address through DNS, and then communicates with IIS through the socket.

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Net; 5 using System.Net.Sockets; 6 using System.Text; 7 8 Namespace MyIIS 9 {Ten using system.threading;11 public class SocketServer12 {Socket serversocket; int port;15 string ip;16 action<string> display;17 18//function public Socketserv ER (int port,string ip,action<string>display) {this.display = display;22 This.ip = IP;           This.port = port;24}26 public void Start () 27 {28//1. Open Socket29 ServerSocket = new Socket (ADDRESSFAMILY.INTERNETWORK,SOCKETTYPE.STREAM,PROTOCOLTYPE.TCP); 30 31//2. Connect the socket to the specified IP and port ipendpoint IPP = new IPEndPoint (Ipaddress.parse (IP), port), Serversocket.bind (IPP ); 34//3 Open Monitoring Serversocket.listen (10); 36 37//4. Waiting for the client to connect. Thread th = new T Hread (ACCEPTCLient); IsBackground = true;41st. Start (); This.display ("Server started successfully"),}45 bool isstop = false;46//Listener client link, privat e void Acceptclient () (!isstop) 50 {51//Accept Client Link-Socke T cSocket = serversocket.accept (), msgsocket thread = new Thread (receivemsg), Msgsocket . IsBackground = true;56 Msgsocket.start (); 57 58}59}60//Accept Client Information----private void Receivemsg (object socket) (Tmpsocket) (socket) socket;65 Ile (!isstop) (byte[) Recbuffer = new byte[1024 * 1024];71 TM Psocket.                   Receive (Recbuffer); Requestmsg string = System.Text.Encoding.UTF8.GetString (Recbuffer); 74 This.display (requestmsg); byte[] ResponseBytes = ISAPIruntime.processrequest (REQUESTMSG); 76//Send content back to browser tmpsocket via socket. Send (responsebytes); 78}79 80 81}82}83}

Second. The IIS server determines the file type.

1) After IIS accepts the request, what type of file is requested, if the request is a static file (for example: Html,js,cs, etc), IIS will directly process, according to the foreground page class URL name, to local find the requested page class, returned to the browser.

2) If it is a dynamic file (for example: Ashx,aspx), IIS finds itself unable to handle the file, then to the mapping table, find an extension called Aspnet_isapi, you can directly handle the ashx,aspx suffix of the dynamic file, and then to the ASP.

Third. Implement the Isapirruntime of the ASP.

Isapirruntime through its ProcessRequest method, HttpContext HttpRequest as a parameter, passed to the Isapirruntime class method, the class created HttpRuntime object.

Third. The HttpRuntime class mainly creates a large amount of objects.

A) Instantiating HttpContext objects

Create 2 large Objects

1) Create HttpContext class

HttpRequest Request message: Mainly the IIS server request message.

The HttpResponse response message is primarily a response to the browser.

HttpServerUtility Property Server: Gets the physical path of the request class primarily.

Remaphandler interface: The main is to save the object of the created requested class

II) Instantiating HttpApplicationFactory objects

The HttpApplicationFactory object creates the HttpApplication object through its PR (ProcessRequest) method.

III) The HttpApplication object probably creates 19 delegate objects.

The HttpApplication object probably creates 19 delegate objects, also known as pipeline events.

1th Pipeline Event

The main is the global capture, you can execute a method here, this method than the method of each page executes first. You can also catch an exception, mostly without being caught by try {}catch{}, and look at the source code in detail.

2–5 Pipeline Events

The main is to request the user's information and page access rights.

第6-7 Pipeline Events

The main is to determine whether the page has a cache, if any, directly read the cache, no longer continue to execute the ASP. If not, do it down.

8th Pipeline Event

Create the requested page class object by reflection, and put it inside the Remaphandler attribute.

第9-10 Pipeline Events

Determines if the page has a valid session, and if it is valid, it will no longer create a session object to the session, while saving SessionID memory on the client.

第11-12 Pipeline Events

Determines whether a static or dynamic page, or a static page, does not have to perform a life cycle. Otherwise, the life cycle is performed. The number of controls created by _buildcontroltree.

Call the life cycle Render method to create the HTML code.

第13-16 Pipeline Events

Frees resources and updates the cache.

第17-18 Pipeline Events

Update the log.

19th Pipeline Event

Execution is complete.

Let's hope that this simple ASP. NET mechanism will be helpful to you, and then we'll go over the details of each event.

Asp. NET mechanism for detailed pipeline event flow

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.