Skip to content

Global.asax 的所有事件

以下是页面请求触发的所有事件,以触发顺序排序:

Application_BeginRequest

当 ASP.NET 开始处理每个请求时触发。在这个事件处理中的代码将在页面或者服务处理请求之前执行。

Application_AuthenticateRequest

在验证请求之前触发。(正如第 12 章介绍的,验证是确认用户就是他所说的那个人的过程)在这个事件处理程序的代码中允许实现自定义安全管道。

Application_AuthorizeRequest

在为请求授权之前触发。(授权是确定是否请求用户具有访问资源的权限的过程,在
第 12 章已经介绍过)在这个事件处理程序的代码中允许实现自定义安全管道。

Application_ResolveRequestCache

在 ASP.NET 确定是否应该生成新的输出,或者由缓存填充前触发。无论何种情况,都将执行该事件处理程序中的代码。

Application_AcquireRequestState

在获取会话状态之前执行。

Application_PreRequestHandlerExecute

在将请求发送到服务于请求的处理程序对象之前触发。当事件触发后,页面将由 HTTP 处理程序处理请求。

Application_PostRequestHandlerExecute

当 HTTP 处理程序与页面请求一起完成时触发。此时,Response 对象将获得由客户端返回的数据。

Application_ReleaseRequestState

当释放和更新试图状态时触发。

Application_UpdateRequestCache

如果输出被缓存,那么缓存更新时将触发。

Application_EndRequest

当请求结束时执行。

Application_PreSendRequestHeaders

在向客户端发送 HTTP 头之前触发。如果启用响应缓存,这意味着直到所有数据都准备好(默认条件),都不会发送任何数据。该事件总是在 Application_EndRequest 事件之后。如果禁用响应缓存,那么无论何时将数据发送给客户端,都将触发该事件。响应控制由 Page 指令的一个属性,或者 Web 服务的 WebMethod 属性控制。

Application_PreSendRequestContent

向客户端发送 HTTP 内容之前触发。和 Application_PreSendRequestHeaders 事件一样,Application_PreSendRequestContent 事件能否被触发取决于响应缓存是否可用。
以下列举应用程序事件,它们在特定条件下触发:

Application_Start

当应用程序启动时触发。当首次请求应用程序虚拟目录中的任何页面时,将启动应用程序,同时如果应用程序已经运行,则不触发该事件。

Application_End

应用程序结束时触发。无论何时修改了配置文件(global.asaxglobal.asax.csglobal.asax.vb 或者 web.config),或者服务器崩溃或者重启,应用程序都将结束。通常在该事件处理程序中执行清除功能的代码,例如关闭数据库连接。

Session_Start

每个会话开始时触发,这是放置具体会话代码的地方。

Session_End

会话结束时触发。它为保存存储在会话中的任何数据提供了机会。

Application_Disposed

当 CLR 从内存中移除应用程序时触发。

Application_Error

无论在应用程序中何时何处发生未处理的错误都将触发。它提供了一个实现通用应用程序错误处理的好机会。
使用 try...catch 语句块能够在代码中处理特定错误,也可以使用 Page 指令的 ErrorPage 属性来捕获页面级错误。使用这些方式处理任何错误都不会触发 Application_Error 事件。


原文:global.asax 所有事件


Page Layout Max Width

Adjust the exact value of the page width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the page layout
A ranged slider for user to choose and customize their desired width of the maximum width of the page layout can go.

Content Layout Max Width

Adjust the exact value of the document content width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the content layout
A ranged slider for user to choose and customize their desired width of the maximum width of the content layout can go.