我有一个名为 Global
的类,它派生自 HttpApplication
。
奇怪的是,我在 Global
中看到很多方法,看起来像:
void Application_Start(object sender, EventArgs e)
{
}
代码肯定是在这个方法内执行的,所以该方法是从某个地方调用的,但是在哪里呢?这些方法没有标记为重载?
其次,我从Global
派生了一个类,我们称之为GlobalFoo
。
同样,如果我创建一个名为 Application_Start()
的方法,它将在我的派生类中被调用,否则 Global
中的任何内容都不会被调用,所以我可能会从一个空的班级。
有人可以提供任何建议吗?我是否缺少 ASP.NET 的某些基本部分?
I have a class called Global
that derives from HttpApplication
.
Oddly, I see a lot of methods inside Global
that look like:
void Application_Start(object sender, EventArgs e)
{
}
The code is definitely executing inside this method, so the method is being called from somewhere, but where? The methods aren't marked overload?
Secondly, I derived a class from Global
, let's call it GlobalFoo
.
Again, if I create a method called Application_Start()
it will get called inside my derived class, otherwise nothing that's in Global
will get called so I might as well be deriving from an empty class.
Can anyone offer any advice? Am I missing some fundamental part of ASP.NET?
发布评论
评论(3)
此函数从应用程序池(从您分配的每个池)调用,以发出应用程序的启动/结束事件信号并帮助您进行初始化。
分配运行 Web 应用程序的每个池都会运行这些功能。
asp.net 正在帮助您创建可以一起运行的外部或外部的不同对象/代码,这就是为什么您会看到所有注册代码都在运行。创建多个具有不同想法的“启动”例程是有帮助的。
这个是一个例子,这个模块只是自己检查安全协议...并且您不需要更改代码上的任何内容,只需注册即可。
This functions are called from the Application Pool (from each pool that you have assign), to signal start-up/end events of your application and help your with initializations.
Every pool that is assign to run your web application runs those functions.
asp.net is helping you create different objects/code external or not that can run together, and that's why you see that all of your registered code run. Its a help to create more than one "start up" routines that do different thinks.
This is an example, this module just check the secure protocol by him self... and you do not need to change anything on your code, just register it.
IIS 通过 asp.net isapi 过滤器调用不同的 Global.asax 事件。
也许这篇文章将有助于解释。
IIS calls the different Global.asax events through the asp.net isapi filter.
Perhaps this article will help explain.
Global.asax 文件是一个可选文件,用于声明和处理在 IIS Web 服务器上运行的 ASP.NET 网站的应用程序和会话级事件和对象。
此文件中的一些关键事件是:
有关 Global.asax 事件的完整列表,请参阅“Global.asax 事件”。
The Global.asax file is an optional file used to declare and handle application and session-level events and objects for an ASP.NET web site running on an IIS Web Server
some of the key events in this file are:
For a complete list of Global.asax events see "Global.asax Events".