Dynamically registering HttpModule in ASP. NET 4.0

Source: Internet
Author: User

usingSystem;usingsystem.web;usingMicrosoft.Web.Infrastructure;namespacemvcapplication1{ Public classCustommodule:ihttpmodule { Public voidInit (HttpApplication context) {context. BeginRequest+=NewEventHandler (context_beginrequest); }        voidContext_beginrequest (Objectsender, EventArgs e) {HttpApplication AP= Sender asHttpApplication; if(AP! =NULL) {ap. Response.Write ("Uncle Tom tested Preapplicationstartmethod through! <br/>"); }        }         Public voidDispose () {// Nothing        }    }     Public classPreapplicationstartcode {Private Static BOOLhasloaded;  Public Static voidPrestart () {if(!hasloaded) {hasloaded=true; //Note The dynamic registration here, this static method in Microsoft.Web.Infrastructure.DynamicModuleHelperMicrosoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule (typeof(CustomModule)); }        }    }}
usingSystem.Reflection;usingSystem.Runtime.CompilerServices;usingSystem.Runtime.InteropServices;//General information about a assembly is controlled through the following//set of attributes. Change these attribute values to modify the information//associated with an assembly.[Assembly:assemblytitle ("MvcApplication1")][assembly:assemblydescription ("")][assembly:assemblyconfiguration ("")][assembly:assemblycompany ("")][assembly:assemblyproduct ("MvcApplication1")][assembly:assemblycopyright ("copyright©2014")][assembly:assemblytrademark ("")][assembly:assemblyculture ("")]//Setting ComVisible to False makes the types in this assembly not visible//To COM components. If you need to access a type in this assembly from//COM, set the ComVisible attribute to true on that type.[Assembly:comvisible (false)]//The following GUID is for the ID of the typelib if this project is exposed to COM[Assembly:guid ("98a0cfd0-fae7-43dd-8626-b49f8df939be")]//Version information for a assembly consists of the following four values:////Major Version//Minor Version//Build Number//Revision////You can specify all the values or you can default the Revision and Build Numbers//by using the ' * ' as shown below:[Assembly:assemblyversion ("1.0.0.0")][assembly:assemblyfileversion ("1.0.0.0")][assembly:system.web.preapplicationstartmethod (typeof(Mvcapplication1.preapplicationstartcode),"Prestart")]

Dynamically registering HttpModule in ASP. NET 4.0

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.