- Global.asax
Global.asax is an optional file used to declare and handle application- and session-level events and objects. Global.asax is the
ASP.NET extension of the ASP Global.asa file. The Global.asax file resides in the IIS virtual root of an ASP.NET application. At run time, upon the arrival of the first request, Global.asax is parsed and compiled into a dynamically generated.NET Framework class. ASP.NET is configured so that any direct request for the Global.asax is automatically rejected, external users cannot view or download the code in it. [ [http://msdn2.microsoft.com/en-us/library/2027ewzw.aspx MSDN: Global.asax Syntax] ]Code to handle application events (such as the start and end of an application) resides 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. Remember that a virtual root can be thought of as the container of a web application. Events and state specified in the global file are then applied to 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.
The ASP.NET Global.asax file can coexist with the ASP Global.asa file. You can create a Global.asax file either in a WYSIWYG designer or as a compiled class that you deploy in your application's "Bin" directory as an assembly. However, in the latter case, you still need a Global.asax file that refers to the assembly.
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".
ee also
References
Wikimedia Foundation. 2010.