使用PreApplicationStartMethodAttribute添加Application_Start事件

先预备一个类,用于Start时调用

public static class MyPreApplicationStart
   {
       public static void RegisterGlobalFilters(GlobalFilterCollection filters)
       {
           if (filters != null)
               filters.Add(new HandleErrorAttribute());
       }
 
       public static void Start()
       {
           RegisterGlobalFilters(GlobalFilters.Filters);
       }
   }
这之后通过PreApplicationStartMethodAttribute注册到assembly即可,需要注意的是自定义类必须public ,其中用记Start的方法必须public static
[assembly: PreApplicationStartMethod(typeof(MyPreApplicationStart), "Start")]

Reference:

http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=ZH-CN&k=k(SYSTEM.WEB.PREAPPLICATIONSTARTMETHODATTRIBUTE);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true

http://msdn.microsoft.com/zh-cn/library/gg401977(v=vs.98)

posted @ 2012-05-11 15:19  重典  阅读(2132)  评论(1编辑  收藏  举报