HTTPMODULE from HTTP processing and application in ASP.NET

xiaoxiao2021-03-06  52

Httphandler implements a function similar to the ISAPI EXTENTION, which handles requests and the SepSe. The implementation of the HTTPHANDLER function is achieved by implementing the IHTTPHANDLER interface. HttpModule implements features similar to the ISAPI Filter. HttpModule's implementation httpModules implements the functionality similar to the ISAPI Filter, which usually needs to pass the following steps: 1. Write a class, implement the IHTTPModule interface 2. Implement the init method, and register the method of registration 3. Implement the registration method 4 Implement the Dispose method, if you need to do some clearance, you can add the DISPOSE method, but this is not required, usually not adding any code to the Dispose method. 5. In the web.config file, registering the class you write below is an example of an HttpModules. In this example, just simply registering the httpApplication's BeginRequest and EndRequest events, and through these events implementation, information print it out. Example 1: using System; using System.Web; namespace MyModule {public class MyModule: IHttpModule {public void Init (HttpApplication application) {application.BeginRequest = (new EventHandler (this.Application_BeginRequest)); application.EndRequest = (new EventHandler (this.Application_EndRequest));} private void Application_BeginRequest (Object source, EventArgs e) {HttpApplication Application = (HttpApplication) source; HttpResponse Response = Application.Context.Response; Response.Write ( "

Beginning of Request

");

End of request

");} Public void dispose ()}}} The start references the following namespace: use system; using system.Web; because httpApplication, httpcontext, httpresponse, etc. are defined in System.Web, so System.Web The namespace must be referenced. MyModule class implements the IHTTPModule interface. In the init method, the method of implementing the BeginRequest and EndRequest events. In these two methods, only simple separately print some information. Below, in the web. If you register this class in the config file, you can use this httpmodule, the registration method is as follows: Now look at the effect. Write an ASPX page Test.aspx, the content is as follows: <% response.write ("this is the page

");%> The interface after run is shown in the figure:

When we develop application systems, the application system's permission control is a very important part. in

ASP

转载请注明原文地址:https://www.9cbs.com/read-82992.html

New Post(0)