Global.asax 中的事件来源是什么?

What is the source of Events in Global.asax?

Global.asax 继承 HttpApplication class。但是HttpApplication并不包含Global.asax的所有事件。那么剩下的事件在哪里呢?它们必须从某个地方继承。他们的来源是什么?

它们不是从任何地方继承的。他们通过 a convention

连接到 Asp.Net 管道

During the application life cycle, the application raises events that you can handle and calls particular methods that you can override. To handle application events or methods, you can create a file named Global.asax in the root directory of your application.

...

ASP.NET automatically binds application events to handlers in the Global.asax file using the naming convention Application_event

最后,这个模型是可扩展的:

If you add modules to your application, the modules themselves can raise events. The application can subscribe to in these events in the Global.asax file by using the convention modulename_eventname.

这就是为什么您可以获得例如此文件中还有与会话相关的事件,例如 Session_Start.