An explanation of the ASP operation mechanism

Source: Internet
Author: User

1. How the browser interacts with the server
    1. Popular Description: We usually through the browser to access the site, in fact, you visit a computer through a browser to access the file, but the browser's access request is accessed by a Web server software on the computer to receive processing, it will analyze the received request information, In order to follow the request information to find files on the server computer, processed, and eventually send the generated content back to the browser.
    2. Simply put: By the browser generated a "command", the Internet to another computer software (server software), the Server Software received "command", the analysis to understand the "command", and then follow the "command" to locate the file on the server computer, the file content sent back to the browser.

    1. Through, we see a simple process of browser and server interaction. Now, we have to think about the browser and server Software is God horse East, how do they interact with information?
    2. In fact, the browser and server software is two separate applications (just like QQ, Office, paint tools). The interaction between the two applications involves the application communication problem. What about the way they communicate with God's horse?
    • The answer is socket:socket. As for the specific use and principle of the socket, the space problem is not written in this article, the first reserved location in this, the next time to fill in the "multi-threaded and socket-based simple webserver software-no control of ASP."
    • Browsers and server software send and receive information through sockets, but the key question now is what they send and receive?---HTTP protocol-based message data (see "HTTP protocol Introduction---ASP. NET with no controls").
    • That is, the browser and server software is actually two of the two applications that use the socket to communicate: Both parties send data organized according to the HTTP protocol syntax specification, and after receiving the data are interpreted in accordance with the HTTP protocol syntax specification.

      2. Browser and IIS (or other webserver) interaction mechanism

is IIS (Server software)

1. Browser and IIS interaction process:
We all know that on the Internet to determine the location of a computer using IP addressing, but why when we usually visit the site directly into a domain name can also access to a server computer and then by the other party's server software to send response page data to me? I'll list the simple steps below:

(1) In the browser input URL: www.oumind.com/index.html, the browser according to the HTTP protocol syntax to generate the request message data.

(2). The browser checks to see if the www.oumind.com/index.html. Domain name corresponds to the server IP address. If not, it sends the request to the nearest DNS server in the city network (the domain name resolution Server), which will be sent back to the server according to the domain name we send to the IP address of the domain name, and then send to the browser.

(3) The browser obtains the server computer IP corresponding to the www.oumind.com/index.html domain name from the DNS server, then sends the request message through the socket to the server computer. (Note: The HTTP protocol specifies that the default port used by the server software is 80, in layman's terms, that is, if the browser accesses a Web site page, the browser by default is to send the request message to server 80 port, and the server is responsible for monitoring the port software is generally server software- For example, the Iis,java tomcat used by ASP. )

(4) IIS receives the request message, parses the request packet, and obtains the requested page path from the/index.html. Determine the suffix name of the page, and if it is a static page (. Html/.jpg/.css/.js, etc.), the contents of the file are read directly by the components of the IIS software, and the content is sent back to the browser via the socket.

(5) But if a dynamic page (. aspx/.ashx) is requested at this time, IIS will not be able to handle it itself (because the IIS software was developed when ASP. NET program does not exist yet). So, IIS goes to its extender mapping table to see if there are extensions that can handle such files based on the requested file suffix name.

The files that are commonly used in our ASPNET are aspnet_isapi.dll. Aspx/.ashx and other corresponding handlers. Such as:

(6) If IIS finds the corresponding handler based on the suffix, it calls the program to process the request message sent by the browser.

IIS itself cannot handle pages such as the ASPX extension, and can only request static files such as HTML to handle pages with an ASPX extension because IIS has an ISAPI filter, which is a COM component.

Asp. NET service when registering to IIS, a Win32 Extended dynamic library Aspnet_isapi.dll is added. and registers the extension with a page extension (such as ASPX) that can be processed inside IIS. After the extension is started, pages that are not processed by IIS are handled in a defined way.

When a client requests a server resource, This HTTP request is intercepted by the Inetinfo.exe process (WWW service), then the check requests the type of the resource and assigns the requested resource to a specific handler module based on the resource mapping information, which is stored in the IIS Meta-Library, an IIS-only configuration database. If the requested static resource (img,text,html, etc.) is handled by IIS (IIS accesses the requested file on the local Web server), the content is output to the console, and the requesting browser is able to receive it.

If a request is to be processed on the server side, it will be uploaded to the registered extension, and the ASPX request will be assigned to Aspnet_isapi.dll, allowing the program to start processing the code, generate standard HTML code, and then add the HTML to the original HTML. Finally, the full HTML is returned to Iis,iis and the content is sent to the customer's browser.

The ASP. NET Framework handles the request :

It says that IIS assigns a page like aspx to Aspnet_isapi.dll, which is then handled as follows:

1. Aspnet_isapi.dll will send this HTTP request to W3wp.exe via an HTTP pipeline pipeline (the IIS worker process, called w3wq.exe,iis5.0 in IIS6.0), This HTTP request is then processed by the ASP. HttpRuntime.

2. httpruntime first determines the class name for processing the request, and httpruntime calls the class through the public interface IHttpHandler to obtain an instance of the class of the requested resource.

3. Call Httpruntime.processrequest to start processing the page to be sent to the browser, specifically to create an HttpContext instance that encapsulates all the HTTP-specific information about the request and initializes a write object for caching the tag code.

4. httpruntime uses contextual information to find or create a new object that can handle the request's Web application. The HttpApplication factory is responsible for returning the HttpApplication instance.

5. The HttpApplication instance reads the configuration of all HttpModule in Web. config.

6. The HttpApplication object uses an instance of the IHttpHandlerFactory type to return the HttpHandler (HTTP handler) to the HttpRuntime object. A page is just an HTTP handler object.
7. The ProcessRequest method that finally calls IHttpHandler's Page object by the HttpRuntime object.

An explanation of the ASP operation mechanism

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.