在Asp.net 4.0 中動態註冊HttpModule

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   io   os   ar   for   

using System;using System.Web;using Microsoft.Web.Infrastructure;namespace MvcApplication1{    public class CustomModule : IHttpModule    {        public void Init(HttpApplication context)        {            context.BeginRequest += new EventHandler(context_BeginRequest);        }        void context_BeginRequest(object sender, EventArgs e)        {            HttpApplication ap = sender as HttpApplication;            if (ap != null)            {                ap.Response.Write("湯姆大叔測試PreApplicationStartMethod通過!<br/>");            }        }        public void Dispose()        {            //nothing to do here        }    }    public class PreApplicationStartCode    {        private static bool hasLoaded;        public static void PreStart()        {            if (!hasLoaded)            {                hasLoaded = true;                //注意這裡的動態註冊,此靜態方法在Microsoft.Web.Infrastructure.DynamicModuleHelper                Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(CustomModule));            }        }    }}
using System.Reflection;using System.Runtime.CompilerServices;using System.Runtime.InteropServices; // General Information about an 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 an 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")]

 

在Asp.net 4.0 中動態註冊HttpModule

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.