使用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")]
摘自 重典的博客
补充:Web开发 , ASP.Net ,