Detailed description of ASP. NET running mechanism, and asp.net Running Mechanism
1. Interaction between browsers and servers
- The answer is socket:Socket. As for the specific usage and principle of Socket, the length issue is not written in this article. First, reserve the location here. Next time, add the simple WebServer Software Based on multithreading and sockets-ASP without controls.. NET.
- Browsers and server software send and receive information from each other through sockets, but the key question is, What exactly are they sending and receiving? --- Http-based message data (For details, refer to Http Protocol Introduction-ASP. NET without controls).
That is to say, the browser and server software are actually two applications that use Sockets for communication: both parties send data organized according to the Http syntax specification, after receiving the data, it is explained according to the Http syntax specification.
2. Interaction between browsers and IIS (or other webserver)
Is IIS (server software)
1. Interaction between the browser and IIS:
We all know that IP addressing is used to determine the location of a computer on the Internet, but why can I directly enter a domain name when accessing a website to access a server computer and send the response page data to me by the server software of the other party? Below I will list the simple steps:
(1) enter the URL www.oumind.com/index.html in the browser to generate request message data according to the HTTP protocol syntax.
(2) the browser checks whether the server IP address corresponding to the www.oumind.com/index.html.domain name is saved on the local machine. If no, send a request to the nearest DNS server (domain name resolution server) in the city network. It will query the IP address of the server corresponding to this domain name based on the domain name we sent, and send it back to the browser.
(3) the browser obtains the IP address of the server computer corresponding to the www.oumind.com/index.html domain name from the DNS server, and then sends the request packet to the server computer through Socket. (Note: The Http Protocol specifies that the default port used by the server software is 80. In other words, if the browser accesses a website page, the browser sends the request message to port 80 of the server by default, the software used by the server to listen to this port is generally server software, such as IIS for asp.net and Tomcat for java .)
(4) IIS receives the request message, analyzes the request message, and obtains the requested page path/index.html. The suffix of the webpage. If it is a static page (.html/. jpg/. css/. js), the content of the file is directly read by the IIS software component and sent back to the browser through Socket.
(5) But if the request is a dynamic page (. aspx /. (Because ASP.. NET program does not exist ). Therefore, IIS will go to its extension ing table to check whether there are any extensions that can process such files based on the requested file suffix.
In ASPNET, the commonly used file. aspx/. ashx and other corresponding processing programs are aspnet_isapi.dll. For example:
(6) If IIS finds the corresponding handler Based on the suffix, it will call this handler to process the request message sent by the browser.
IIS itself cannot process pages such as ASPX expansion names. It can only directly request static files such as HTML. The reason why it can process pages with extensions such as ASPX is that IIS has an ISAPI filter, it is a COM component.
When the ASP. NET service is registered with IIS, it will add a Win32 dynamic extension library aspnet_isapi.dll. And register the page extension (such as ASPX) that can be processed by the extension to IIS. After the extension is started, it processes pages that cannot be processed by IIS according to the defined method.
When the client requests a server resource, the HTTP request will be intercepted by the inetinfo.exe process (www Service), then Check the type of the requested resource, and based on the resource ing information (stored in the IIS metadatabase, a configuration database dedicated to IIS) allocate the requested resources to a specific handler module. If the requested static resources (img, text, html, etc.) are processed by IIS (IIS accesses the requested file on the Local Web Server), and the content is output to the console, the browser that sends the request can receive it.
Requests that need to be processed on the server side will be uploaded to the registered extension module, and the aspx request will be allocated to aspnet_isapi.dll, so that the program can start to process the code, generate standard HTML code, add the HTML to the original HTML, and finally return the complete HTML to IIS. IIS then sends the content to the client's browser.
Processing requests using ASP. NET FrameWork:
As mentioned above, IIS assigns pages like ASPX to aspnet_isapi.dll, and then processes them as follows:
1. aspnet_isapi.dll uses an Http listener (iis Worker Process, w3wq.exe in IIS6.0, and aspnet_wp.exe in IIS5.0). Then the asp.net framework processes the Http request through HttpRuntime.
2. HttpRuntime first determines the class name for processing the request. HttpRuntime calls the class to obtain the instance of the requested class through the public interface IHttpHandler.
3. Call HttpRuntime. processRequest starts to process the page to be sent to the browser. Specifically, it creates an HttpContext instance which encapsulates all http-specific information related to the request and initializes a Write object to cache the markup code.
4. HttpRuntime searches for or creates an object for a WEB application that can process the request using context information. HttpApplication Factory is responsible for returning the HttpApplication instance.
5. The HttpApplication instance reads the configurations of all httpmodules in web. config.
6. The HttpApplication object uses an IHttpHandlerFactory-type instance to return HttpHandler (http handler) to the HttpRuntime object. A page is just an http handler object.
7. Finally, the HttpRuntime object calls the ProcessRequest method of the IHttpHandler Page Object.