HTTP module of ASP. NET and request handling process of processing programs

Source: Internet
Author: User

Processing of ASP. NET requests

The ASP. NET Request Processing process is based on the pipeline model. In the model, ASP. NET passes the http request to all modules in the pipeline. Each module receives http requests and has full control permissions. The module can process requests in any way that it deems appropriate. Once the request passes through all the HTTP modules, it is finally processed by the HTTP processing program. The HTTP handler processes the request and the result will go through the HTTP module in the pipeline again:

 

Note that only one http handler can be called during HTTP request processing, but multiple HTTP modules can be called.

Http handler

The HTTP handler is A. NET component that implements the System. Web. IHttpHandler interface. Any class that implements the IHttpHandler interface can be used to process input HTTP requests. The HTTP handler is similar to the ISAPI extension. The difference between HTTP processing programs and ISAPI extensions is that they can be directly called using the file names of HTTP processing programs in URLs, similar to ISAPI extensions.

The HTTP handler implements the following methods:

Method Name Description
ProcessRequest This method is actually the core of the http processing program. We call this method to process http requests.
IsReusable We call this attribute to determine whether the http handler instance can be used to process requests of the same type. HTTP handlers can return true or false to indicate whether they can be reused.

You can use the web. config or machine. config file to map these classes to http requests. After the ing is completed, ASP. NET will instantiate the http processing program when it receives the corresponding request. We will explain how to define all these details in the web. config and/or machine. config files.

ASP. NET also supports http processing program extension through the IHttpHandlerFactory interface. ASP. NET provides the ability to route http requests to objects of classes that implement the IHttpHandlerFactory interface. In addition, ASP. NET also utilizes the Factory design mode. This mode provides an interface for creating a group of related objects without providing the function of a specific class. To put it simply, you can regard the class of the http handler object used to establish the parameters passed in by dependencies as factory ). We do not need to specify the specific http handler to be instantiated; the http handler factory handles such transactions. The advantage of this is that if the implementation method of the object implementing the IHttpHandler interface changes in the future, the client will not be affected as long as the interface is still the same.

The following is a list of methods in the IHttpHandlerFactory interface:

Method Name Description
GetHandler This method establishes an appropriate handler and returns its pointer to the calling code (ASP. NET runtime ). The handler object returned by this method should implement the IHttpHandler interface.
ReleaseHandler This method releases the http processing program after the request is processed. The Factory implementation determines its operations. The Factory implementation can actually destroy the instance, or put it into the buffer pool for future use.

Register an HTTP handler and an HTTP handler factory in the configuration file

ASP. NET maintains its configuration information in the following configuration file:

· Machine. config

· Web. config

The machine. config file contains configuration settings for all Web applications installed on the computer.

The web. config file is specific to each Web application. Each Web application has its own web. config file. Any subdirectory of the Web application may also contain its own web. config file, which allows them to overwrite the settings of the parent directory.

To add HTTP handlers to our Web applications, you can use

 
 
  1. <httpHandlers>  
  2.  <add verb="supported http verbs" path="path" type="namespace.classname, assemblyname" />  
  3. <httpHandlers> 

In the preceding XML,

The Verb attribute specifies the HTTP action supported by the handler. If a processing program supports all HTTP actions, use "*". Otherwise, use a comma-separated list to list supported actions. Therefore, if your handler only supports http get and POST, the verb attribute should be "GET, POST ".

· The Path attribute specifies the Path and file name of the handler to be called (which can contain wildcards ). For example, if you want your handler to be in the test. the xyz file is called only when it is requested, so the path attribute contains "test. xyz ", if you want to include. all files with the xyz suffix call the handler. The path attribute should contain "*. xyz ".

· The Type attribute specifies the actual Type of the handler or handler factory in the form of a combination of namespace, class name, and part name. When ASP. NET is running, search for the part DLL in the bin directory of the application, and then search in the global part buffer (GAC.

  1. HTTP module and processing program of ASP. NET
  2. Execution of the HTTP module and processing program of ASP. NET
  3. Session Status of HTTP modules and handlers of ASP. NET
  4. Registration and use of the HTTP module of ASP. NET and the HTTP module of the processing program
  5. ASP. net http module and processing program module implementation

Related Article

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.