<span id="Label3"></p><p><p>IHttpModule provides module initialization and disposition events to the implementation class.<br>IHttpModule contains two methods:</p></p><p><p>public void Init (httpapplication context);<br>public void Dispose ();<br><br><strong>Init ()</strong>: This method accepts an HttpApplication object, HttpApplication represents the current application, and we need to register the event that the HttpApplication object exposes to the client within this Method. visible, This method is only used to register the event, and the actual event handler, we need to write another method.<br><br>The whole process is well understood:<br><br>1. When the Site's first resource is accessed, asp. NET creates an instance of the HttpApplication class that represents the site application and creates all the module instances registered in Web. Config.<br>2. The init () method of Modul is called when the module instance is Created.<br>3. Within the init () method, register the event exposed by the HttpApplication that you want to respond to. (the actual method needs to be written separately, simply by simply registering the method).<br>4. HttpApplication triggers various events in its application Cycle.<br>5. Invoke the method that the module registered in its init () method when the event is Triggered.<br><br><strong>Dispose ()</strong>: It can do some cleanup work before garbage Collection.</p></p><p><p> Public class Moduledemo:ihttpmodule <br> {<br> public void Init (httpapplication Context) {<br> // registering HttpApplication applications BeginRequest events <br> // can also be any other HttpApplication exposed event <br> Context. BeginRequest + = new EventHandler (context_beginrequest); <br> } <br> <br> void context_beginrequest (object sender, EventArgs e) {<br> HttpApplication application = (httpapplication) sender; <br> HttpContext context = Application. Context; <br> // do some practical work, HttpContext objects are obtained, the rest of the basic can be free to play the <br> <br> <br> public void Dispose () {<br> } <br>} </p></p><p><p>In the implementation of Dispose this method is, many people are accustomed to add, thisdispose () this code, plus, in the actual debugging will appear Stockoverfllow exception, the solution is that the method is not to do any processing of an empty method,</p></p><p><p>IHttpModule Interface Considerations for Asp.</p></p></span>
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