HttpApplication.Start event does not exist

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-05 08:36:12

问题


I looked for an answer to this for quite sometime now but didn't find any.

I will refer to Application start as a stage.

Most of the documentations out there talk about the Global.asax file and the Application_Start method which is invoked only once when the first request reaches the Application, even if this behaviour is similar to subscribing to an event it's technicaly not an event.

While lifecycle events such as BeginRequest, AuthenticateRequest and so on are accessible through the application instance as events, the Application.Start is not.

I can subscribe to BeginRequest event in an HttpModule.Init() method or Global.asax Init() method but not to the Application.Start stage like so:

Module

public class MyModule : IHttpModule
{
  public void Init(HttpApplication httpApplication)
  {
    httpApplication.BeginRequest += new EventHandler(ApplicationBeginRequest);
  }
}

Global

public class Global : HttpApplication
{
  public override void Init()
  {
    BeginRequest += new EventHandler(ApplicationBeginRequest);
  }
}

After jumping to the .NET source code i found that the HttpApplicationFactory class looks for a method named "Application_OnStart" or "Application_Start" in the Global.asax file and then invokes it using reflection => ReflectOnMethodInfoIfItLooksLikeEventHandler().

My question:

Since HttpApplication.Start is not an event and not accessible from the Application instance in other fashions, is Global.asax and the "Application_OnStart" or "Application_Start" methods the only hope to add code at this applicative level ?

来源:https://stackoverflow.com/questions/54650631/httpapplication-start-event-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!