What is the purpose of global.asax in asp.net

前端 未结 6 636
无人及你
无人及你 2020-12-12 10:19

How can we use global.asax in asp.net? And what is that?

6条回答
  •  无人及你
    2020-12-12 10:40

    MSDN has an outline of the purpose of the global.asax file.

    Effectively, global.asax allows you to write code that runs in response to "system level" events, such as the application starting, a session ending, an application error occuring, without having to try and shoe-horn that code into each and every page of your site.

    You can use it by by choosing Add > New Item > Global Application Class in Visual Studio. Once you've added the file, you can add code under any of the events that are listed (and created by default, at least in Visual Studio 2008):

    • Application_Start
    • Application_End
    • Session_Start
    • Session_End
    • Application_BeginRequest
    • Application_AuthenticateRequest
    • Application_Error

    There are other events that you can also hook into, such as "LogRequest".

提交回复
热议问题