ASP. NET operating mechanism Principle
--- Interaction process between browser and IIS
I. Interaction between browsers and servers
(I)A brief description of the interaction between the browser and the server:
1. popular Description: We usually access the website through a browser, which is equivalent to accessing a file on a computer through a browser, however, a browser's access request is received and processed by a web server software on the accessed computer. It analyzes the received request information, in this way, the files on the server computer are found according to the request information. After processing, the generated content is sent back to the browser.
Simply put, a "command" is generated by a browser and sent to a software (server software) on another computer over the Internet. The server software receives the "command ", analyze and understand the "command", and then find the file on the server computer according to the "command", and send the file content back to the browser.
2. We can see a simple process of interaction between the browser and the server. Now, let's think about how browsers and server software interact with each other?
In fact, browsers and server software are two independent applications (just like QQ, office, and drawing tools ). The interaction between two applications involves application communication. What if they use Shenma to communicate with each other?
The answer is:Socket:Socket. As for the specific usage and principle of the socket, the length issue is not written in this article. First, reserve the location here and add it next time.Simple multi-thread and socket-basedWebserverSoftware-No controlsASP. 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? ---Based onHTTPProtocol packet data(For details, see《HTTPProtocol Introduction---No controlsASP. NET").
That is to say:Browser and server softwareActually there are twoUseSocketTwo applications for communication: Both parties send data organized in accordance with the HTTP protocol syntax specification. After receiving the data, the data is interpreted in accordance with the HTTP protocol syntax specification.
(II), Browsers andIIS (or other webserver)Interaction Mechanism
YesIIS (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 and generate the browser according to the HTTP protocol syntax.Request MessageData.
(2) check whether the server IP address corresponding to www.oumind.com/index.html. domain name is saved in the browser. 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) If the browser obtains the IP address of the server corresponding to the domain name www.oumind.com/index.html from the DNS serverRequest MessageIt is sent 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 itsExtended ing tableAccording to the requested fileSuffixCheck whether the file can be processedExtended Program.
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.
Follow the steps below:
ASP. Net Operating Mechanism principle 02_asp.net overall operating mechanism 01 from the browser to httpapplication --- ASP. NET without controls
Reprint please indicate the source: ASP. NET Operating Mechanism principle 01 --- the process of interaction between browser and IIS Kaizhi network http://www.oumind.com
ASP. NET page Running Mechanism and request processing process
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 group. 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 httprequest will be intercepted by the inetinfo.exe process (WWW Service), then check the type of the requested resource, and store the request in the IIS MetaStore according to the resource ing information, A configuration database dedicated to IIS) allocates 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.
ASP. NET Framework processing of requests:
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.
5. 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.
6. Finally, the httpruntime object calls the processrequest method of the ihttphandler Page Object.