Question 1: What is HttpHandler?
Question 2: What is HttpModule?
Question 3: When should I use HttpHandler to use HttpModule?
The answer to the 1:httphandler,http of the request, such as Scripthandler, Webservicehandler,ihttphandler, is to handle a class of requests. such as Scripthandler is responsible for processing requests to the script.
Answer 2:httpmodule,http module. is actually the handler for the 19 standard events, or 19 subscribers to the standard event, such as Outputcachemodule,sessionstatemodule. Details can be found in this article to see http://www.cnblogs.com/kissdodog/p/3527922.html.
I. Duties of HttpHandler
1, because the HTTP request has many kinds of request types, such as request aspx, HTML, JPG and so on. Therefore, it is very bloated and not conducive to the expansion simply by HttpApplication processing requests directly. Therefore, ASP. NET uses an abstract factory pattern to process these requests. ASP. NET in the schema of the Web. config, allows us to make certain requests mapped to a httphandlerfactory.
<!--configuration for IIS6--><system.web>
So, we should understand this httphanlder: a httphanlder is used to respond to a class of requests, generating response results for a class of requests.
What are the httphanlder that we often use?
1. aspx page.
2. asmx service file.
3. ashx file (generic handler).
4. Implement the custom type of the IHttpHandler interface.
What do we usually do with Httphanlder?
| Httphanlder type |
Achieve goals |
| ASPX page |
Output HTML results in response to ASPX requests |
| ASMX service file |
Response Service Invocation |
| ashx file (Generic handler) |
Implement a simple Ajax response |
| Implementing a custom class for the IHttpHandler interface |
In response to what extension is the request? |
Ii. responsibilities of the HttpModule
Sometimes some pages require the same checking functionality, such as authentication. Obviously using HttpHandler is inconvenient, because not all pages need to call those same features.
HttpModule's design provides a flexible way to solve this function reuse problem, it uses the event (Observer) design pattern, the function that some httphandler need to extract, form different observer types, these observer types can be compiled into a class library form, For sharing with multiple websites. To make the ASP. NET pipeline more flexible, ASP. NET allows us to freely configure the required HttpModule in Web. config.
<!--configuration for IIS6--><system.web>
The configuration simply tells ASP. These HttpModule need to be run and may be useful.
What are we going to do with HttpModule?
1. Modify some requests (for example, the previous example modifies the response header).
2. Check for check requests (such as authentication checks).
What requests can HttpModule handle?
1. The default is for all requests to enter ASP.
2. If only a portion of the request needs to be processed, then make your own judgment.
Iii. SummaryHttpHandler equivalent to a water pipe, httpmodule equivalent to a bar of water. HttpHandler has a lot of strips, a flow of oil, a water and so on. HttpModule is the equivalent of a small cut, the need to filter the long pipe inside can be installed.
. NET Learning Notes---httphandle and httpmodule