Server-side technology-http request processing process

Source: Internet
Author: User
HTTP Request Processing

HTTP requests first reach the Web server, which can be IIS, appache, and so on. These servers can all have their own interface extensions to enhance their functions, among them, IIS uses ISAPI extension to enhance functions, and Asp.net is a type of ISAPI extension.

IIS uses the extension of the requested resource to determine which ISAPI extension is used to process the request. Therefore, if a resource with a certain extension needs to be processed by Asp.net, you need to configure the extension in IIS with the C:/Windows/microsoft.net/framework/v2.0.50727/aspnet_isapi.dllto apply for the type (get, post, etc ).

HTTP requests are processed through several httpmodules (one of which is sessionstatemodule, used to manage session status) and one httphandler. The specific httphandler can be used in the web. configuration in config, any class that implements the ihttphandler interface can be in the web. the config file is configured as an httphandler to process HTTP requests. If it is implemented using the ashx file, it is automatically configured and does not need to be configured on the web. config.

The ihttpmodule interface has two methods: Init () and dispose (). httpmodule is generally used to bind events in init to handle an event in httpapplication, typical applications include authenticaterequest. Httphandler is a processing program that can be configured to process resources with specific extensions. There are two differences between httphandler and web page, that is, no response. clearcontent (), directly set response. contenttype and write can enable programmers to focus on Coding Logic, and then implement the irequiressessionstate interface when they need to access the session.

If the application_beginrequest event is processed in multiple httpmodules, not all of them are executed, because when an exception occurs in an execution of application_beginrequest, the following several will not execute application_beginrequest again, however, if application_endrequest exists, it will be executed because resources need to be released.

The ihttphandler interface has two members: isreusable and processrequest ().

The ihttphandlerfactory interface has two members: gethandler () and releasehandler (). Classes implementing this interface can be configured as httphandler factories in Web. config to route httprequest to the appropriate handler.

If the requested resource is An ASPX page, first check whether the page is compiled. If not, compile it first and then use an instance of it to process the request. Before compiling this page, top-level items will be compiled, such as app_globalresources, app_webresources, profile properties defined in the web. config file, app_code, and global. asax. After the execution, the folders, pages, and other required projects will be compiled based on the requirements for processing the request.

Note that top-level items will only be compiled once. It will only be re-compiled when the dependent items such as Web. config change.

The compiled assembly will be cached on the server. Therefore, except for the first request, it will wait for a long Compilation Time, and future requests will be fast. Of course, you can also pre-compile the assembly, make the first request fast.

1. IIS uses the requested file extension to map to the ISAPI extension, which is configurable. Asp.net is a type of ISAPI extension that can process. aspx,. ascx,. ashx, And. asmx. When a resource with a custom extension needs to be processed by Asp.net, the extension and aspnet_isapi.dll must be mapped.

2. when the first request arrives, applicationmanager creates an application domain, which isolates applications from global variables and allows each application to be detached. In the application domain, the hostingenvironment instance is created, which provides access to application information, such as the folder name that stores the application.

3. After the application domain is created and the hostingenvironment is instantiated, Asp.net creates and initializes core objects, such as httpcontext, httprequest, and httpresponse. Httpcontext contains the objects specific to the current application request, such as httprequest and httpresponse. httprequest contains information about the current request, including cookie and browser information. httpresponse includes the response sent to the browser, including all the rendering outputs and cookies.

4. Specify an application object for the request. After all core objects are initialized, the application starts to create an httpapplication object. The httpapplication object is reusable, that is, it is created during the first request, all future requests use the object created for the first time. When an application has a global. asax file, Asp.net creates a global. asax instance that inherits from the httpapplication class and uses this derived class to process the application. After the application class is created, all configured httpmodules are also created, and application Init () is called.

The Event Sequence of the httpapplication object is:

First, validaterequest is used to check whether there is a potentially malicous markup.

Then, check whether urlmappingssection is configured in the web. config file. If yes, run URL Mapping.

Finally, execute the following:

1. beginrequest
2. authenticaterequest-postauthenticaterequest
4. authorizerequest-postauthorizerequest
6. resolverequestcache-postresolverequestcache

Then select a suitable handler Based on the ing between the extension and handler in the configuration file, or select a suitable handler Based on handlerfactory to process the request. If a webpage is requested and the page needs to be compiled, Asp.net will compile the page before generating the instance of the page.

8. postmaprequesthandler
9. acquirerequeststate-postacquirerequeststate
11. prerequesthandlerexecute

Call the processrequest () method of the appropriate httphandler class. If the method is asynchronous, The beginprocessrequest () method is called. For example, if a webpage is requested, an instance of the page will process the request.

12. postrequesthandlerexecute
13. releaserequeststate-postreleaserequeststate

Then, if the filter attribute is defined, responsefiltering is executed.

15. updaterequestcache-postupdaterequestcache
17. logrequest-postlogrequest
19. endrequest

 

 

 

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.