The Global.asax file is used to implement application events and session level, such as:
Application_Init - Runs when the application first initializes.
Application_Start - starts when the application is first launched
Application_End - The final event that was fired when the application expired or expired.
Session_Start - Runs on the first start of a user session.
Application_BeginRequest - runs with each new request
Application_EndRequest - launched when the application terminates
Application_AuthenticateRequest - an event indicates that the request is ready for authentication.
Application_Error - fires when an unhandled error occurs in the application
Session_End - triggered whenever a single user session ends or time runs out.
Implementing these handlers may be a legitimate use of global.asax. For example, the Application_Error event handler typically logs any global errors, and the Application_End event handler typically contains application cleanup logic. This is a good use of Global.asax. Use them when necessary, and don't be afraid if the file grows.
However, I saw cases where developers added all the global methods to global.asax, which are really not justified. For example, drive business logic associated with a specific domain object within the object itself, and not in global.asax. If you find methods in Global.asax that shouldn't have refactoring, work in the right place.
Joe ratzer
source share