对 global.asax 感到困惑吗?

发布于 2024-09-26 18:49:11 字数 493 浏览 5 评论 0 原文

我有一个名为 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苏辞 2024-10-03 18:49:11

所以该方法是从某个地方调用的,但是在哪里呢?

此函数从应用程序池(从您分配的每个池)调用,以发出应用程序的启动/结束事件信号并帮助您进行初始化。

分配运行 Web 应用程序的每个池都会运行这些功能。

asp.net 正在帮助您创建可以一起运行的外部或外部的不同对象/代码,这就是为什么您会看到所有注册代码都在运行。创建多个具有不同想法的“启动”例程是有帮助的。

这个是一个例子,这个模块只是自己检查安全协议...并且您不需要更改代码上的任何内容,只需注册即可。

so the method is being called from somewhere, but where?

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.

彻夜缠绵 2024-10-03 18:49:11

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.

幸福不弃 2024-10-03 18:49:11

Global.asax 文件是一个可选文件,用于声明和处理在 IIS Web 服务器上运行的 ASP.NET 网站的应用程序和会话级事件和对象。

此文件中的一些关键事件是:

  • Application_Init:当应用程序首次初始化。
  • Application_Start:应用程序第一次启动时触发。
  • Session_Start:当用户会话启动时第一次触发。
  • Application_BeginRequest:每次新请求进入时触发。
  • Application_EndRequest:当应用程序终止时触发。
  • Application_AuthenticateRequest:指示请求已准备好进行身份验证。
  • Application_Error:当应用程序中发生未处理的错误时触发。
  • Session_End:每当单个用户会话结束或超时时触发。
  • Application_End:当应用程序结束或超时时触发(通常用于应用程序清理逻辑)。

有关 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:

  • Application_Init: Fires when the application initializes for the first time.
  • Application_Start: Fires the first time an application starts.
  • Session_Start: Fires the first time when a user’s session is started.
  • Application_BeginRequest: Fires each time a new request comes in.
  • Application_EndRequest: Fires when the application terminates.
  • Application_AuthenticateRequest: Indicates that a request is ready to be authenticated.
  • Application_Error: Fires when an unhandled error occurs within the application.
  • Session_End: Fires whenever a single user Session ends or times out.
  • Application_End: Fires when the application ends or times out (Typically used for application cleanup logic).

For a complete list of Global.asax events see "Global.asax Events".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文