在Asp.net 4.0 中动态注册HttpModule
2024-08-25 14:49:10
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")]
最新文章
- ABP源码分析三十八: ABP.Web.Api.OData
- OC基础--Xcode 模板修改和文档安装
- IDE-Sublime【1】-JsFormat插件格式化缩进问题
- 如何让我们的VMware虚拟机上网——转载
- [转]GridView排序——微软提供Sort
- new Date()时间对象
- uva 11020 - Efficient Solutions ——平衡BST
- bzoj 3489: A simple rmq problem k-d树思想大暴力
- 关于弹出层(iframe)时刷新页面的js
- Top 10 Books For Advanced Level Java Developers
- 编写原生JS的insertAfter函数
- ORA-00257: archiver error. Connect internal only, until freed.| Oracle数据库归档日志满导致应用系统反应缓慢的问题处理
- 学习 ASP.NET Core 2.1:集成测试中使用 WebApplicationFactory
- better-scroll使用总结
- PyQt5 的几个核心模块作用
- PWA 入门: 写个非常简单的 PWA 页面
- FunDA(7)- Reactive Streams to fs2 Pull Streams
- Django实现支付宝支付(沙箱)
- webgote的例子 数据库与sql注入的相关联系(1)
- ORA-**,oracle 12c操作问题