Question 1: What is httphandler?
Question 2: What is httpmodule?
Question 3: When should I use httphandler and httpmodule?
Answer 1: httphandler is the handler of HTTP requests, such as scripthandler, webservicehandler, and ihttphandler. For example, scripthandler is responsible for processing requests to the script.
Answer 2: httpmodule and HTTP module. It is actually the handler of 19 standard events, or the subscriber of 19 standard events, such as outputcachemodule and sessionstatemodule. For details, see http://www.cnblogs.com/kissdog/p/3527922.htmlin this article.
1. httphandler's Responsibilities
1. There are many types of HTTP requests, such as aspx, HTML, and jpg requests. Therefore, it is very bloated to process requests directly by httpapplication, and it is not conducive to expansion. Therefore, Asp.net adopts the abstract factory mode to process these requests. In the Web. config architecture, Asp.net allows us to map certain requests to an httphandlerfactory.
<! -- Applies to IIS6 configuration --> <system. web>
Therefore, we should understand httphanlder as follows:An httphanlder is used to respond to one type of requests and generate response results for one type of requests.
What are httphanlder we often use?
1. ASPX page.
2. asmx service file.
3. ashx file (General handler ).
4. Implement the custom type of the ihttphandler interface.
What do we usually do with httphanlder?
| Httphanlder type |
Goals |
| ASPX page |
Responds to aspx requests and outputs HTML results |
| Asmx service file |
Respond to service calls |
| Ashx file (General handler) |
Implement simple Ajax response |
| Custom class implementing the ihttphandler Interface |
What extension response request? |
Ii. Responsibilities of httpmodule
Sometimes some pages require the same check functions, such as identity authentication. Obviously, using httphandler is inconvenient, because not all pages need to call the same functions.
The Design of httpmodule provides a flexible way to solve this problem of function reuse. It uses the event (observer) design mode to extract the functions required by some httphandler, form different observer types. These observer types can be compiled into class libraries for sharing by multiple websites. To make the ASP. NET pipeline more flexible, ASP. NET allows us to freely configure the required httpmodule in Web. config.
<! -- Applies to IIS6 configuration --> <system. web>
The configuration only tells ASP. Net that these httpmodules need to be run and may be used.
What can we do with httpmodule?
1. modify some requests (for example, the response header is modified in the previous example ).
2. Check the check request (for example, identity authentication check ).
What requests can the httpmodule process?
1. By default, all requests are sent to ASP. NET.
2. If you only need to process part of the request, please make your own judgment.
Iii. Summary
Httphandler is equivalent to a pipe, and httpmodule is equivalent to a pipe. Httphandler has many lines, such as oil and water. Httpmodule is equivalent to a small part and can be installed in the long pipe to be filtered.