Global.asax in ASP.net


  • The Global.asax is also known as the ASP.NET application file and is used to serve application-level and session-level events.
  • It allows us to write code that response to global application events raised by ASP.NET or by HttpModules.
  • These events fire at various points during the lifetime of a web application, including when the application domain is first created.
  • The Global.asax file resides in the root directory of an ASP.NET-based application
  • At run time, global.asax is parsed and compiled into a dynamically generated .NET Framework class derived from the HttpApplication base classThe Global.asax file is optional. If you do not define the file, the ASP.NET page framework assumes that you have not defined any application or session event handlers
Basic Application Events
S. No.
Event Handling Method
Application_Start() event occurs when the application starts, which is the first time it receives a request from any user. It doesn’t occur on subsequent requests. This event is commonly used to create or cache some initial information that will be reused later.
Application_End() event occurs when the application is shutting down, generally because the web server has restarted. You can insert cleanup code here.
Application_BeginRequest() event occurs with each request the application receives, just before the page code is executed.
Application_EndRequest() event occurs with each request the application receives, just after the page code is executed.
Session_Start() event occurs whenever a new user request is received and a session is started.
Session_End() event occurs when a session times out or is programmatically ended. This event is only raised if you are using in-process session state storage (the InProc mode, not the StateServer or SQLServer modes ).
Application_Error() event occurs in response to an un-handled error.

Sample Global.asax file:

A detailed clarification on Globals.asax is discussed in code project article.
Global.asax in Code project

© 2015, www.techkatak.com. All rights reserved.

One thought on “Global.asax in ASP.net

Comments are closed.