What is the global.asax file ?

October 28, 2007 · Filed Under ASP.Net Interview Questions, Placement Questions 



Don't want to miss a single bit? Subscribe By Email for Daily Jobs

Enter your email address :

All the latest from JobsAdda on Jobsadda.com delivered to your mailbox everyday.

Global.asax is a file used to declare application-level events and objects. Global.asax is the ASP.NET extension of the ASP Global.asa file. Code to handle application events (such as the start and end of an application) reside in Global.asax. Such event code cannot reside in the ASP.NET page or web service code itself, since during the start or end of the application, its code has not yet been loaded (or unloaded).

Global.asax is also used to declare data that is available across different application requests or across different browser sessions. This process is known as application and session state management. The Global.asax file must reside in the IIS virtual root.

Events and state specified in the global file are then applied to ASP.NET all resources housed within the web application. If, for example, Global.asax defines a state application variable, all .aspx files within the virtual root will be able to access the variable. Like an ASP.NET page, the Global.asax file is compiled upon the arrival of the first request for any resource in the application. The similarity continues when changes are made to the Global.asax file; ASP.NET automatically notices the changes, recompiles the file, and directs all new requests to the newest compilation. A Global.asax file is automatically created when you create a new web application project in the VS.NET IDE.

Global.asax files consist of the following elements:

1. Event Declarations: Define event delegates, such as OnStart (), that are global to an application.
2. Application Directives: Compiler-specific settings such as import statements.
3. Object Tag Declarations: Instances of objects that are globally accessible (state application variables).

Related Articles


Get Latest JobsAdda.com Jobs, news & updates  via Email