.netASP.net

Global.asax in ASP.net

Global.asax:

  • 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
Description
1
Application_Start()
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.
2
Application_End()
Application_End() event occurs when the application is shutting down, generally because the web server has restarted. You can insert cleanup code here.
3
Application_BeginRequest()
Application_BeginRequest() event occurs with each request the application receives, just before the page code is executed.
4
Application_EndRequest()
Application_EndRequest() event occurs with each request the application receives, just after the page code is executed.
5
Session_Start()
Session_Start() event occurs whenever a new user request is received and a session is started.
6
Session_End()
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 ).
7
Application_Error()
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.