1. Request for HTTP Handler ASP.NET is based on a Pipeline model, ASP.NET sends all HTTP requests to the HTTP component in this pipe. Each component performs some corresponding actions after receiving the HTTP request. When the HTTP request passes all HTTP Modules programs, it will be handled by an HTTP Handler program, and the processed result will return to HTTP Modules in the pipe. During this whole process, the called HTTP Module can have multiple, however the HTTP Handler that is called can only be one. The process is as follows:
It can be seen that each input HTTP request will eventually be processed by an HTTP Handler program. HTTP Handler is an instance of a class that implements the System.Web.ihttPHandler interface, some similar to ISAPI extensions. In HTTP Handler, it is: ProcessRequest: This method is used to process HTTP requests. It is the most core method of HTTP Handler isreusable: A property, returns a BOOL value to indicate whether this HTTP Handler can be reused to process multiple The same type of HTTP request.
Second, the class registered with the HTTP Handler HTTP Handler in the configuration file can be registered in the web.config or machine.config file. This way, once there is a corresponding HTTP request input, this HTTP Handler class will be instantiated. In Web.config or Machine.config files we use
In
In fact, many features in ASP.NET themselves are also implemented using HTTP Handlers, ASP.NET uses many Handler classes to handle .aspx, .asmx, .soap, and some other ASP.NET files. You can find the following code in the machine.config file:
Third, the implementation of the HTTP Handler class Here we use C # to create a new Handler class to handle new file types, such as files that are .possible as the suffix. 1. Let's create a web application in VS.NET, named myHandler, then add a class file newhandler.cs to establish a class that implements the IHTTPHANDLER interface:
Using system; using system.Web;
Namespace myHandler {///
#region Implementation of IHttpHandler public void ProcessRequest (System.Web.HttpContext context) {HttpResponse objResponse = context.Response; objResponse.Write ( "
Public Bool IsReusable;}} #endregion}} In the implementation of the ProcessRequest method, we just get HTTPRESPRESPRESPRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespRespResponse objects, and some HTMLs are sent. Returns true in the ISREUSABLE implementation, indicating that instances of the Handler class can handle a request for multiple pairs .possible files. Note: If you want to use Session in HTTP Handlers, you also need to implement the IREQUIRESSESSIONSTATE interface, and the IRequiresSessionState interface is just a flag, so you don't need to implement any specific methods, so you only need to change the classes to: public class newhandler: httphandler, IrequiressessionState can.
2, open the web.config file, register the newly created Handler class:
3, add ISAPI extensions to add our new compact name .possible, the specific process is: IIS - "Select the" Default website "to right -" Select "Properties -" "Main Directory" - "Configuration" - "Add" button - "Add" button - "In the pop-up dialog box, click the" Browse "button, select the ASPNET_ISAPI.dll file, and fill in the Possible in the extension, as shown below :
Finally click the OK button.
This way we can enter http://localhost/myhandler/xxx.possible in your browser to call this handler. Of course, we just got a simple example here, so enter any * .possible is the same effect. We can first analyze the requested URL in NewHandler, and then make different corresponding corresponding to different URLs, such as jump to different real-existing ASPX pages, which is also the MVC mode in the web design mode in ASP.NET One of the core parts implemented by Front Controller, please see: http://msdn.microsoft.com/architecture/patterns/default.aspx? Pull = / library / en-us / dnpatterns / html / desfrontcontroller.asp.