Briefly describe the role of global.asax
This was asked by one of my friend in the same discussion mentioned in prev blog, who recently started learning .Net. He worked on lot of VB & ASP projects and wanted to know is Global.asax something similar to Global.asa in Classic ASP.
My answer to him is below:
The Global.asax file, also known as the ASP.NET application file, It is an optional file that contains code for responding to application-level events raised by ASP.NET or by HttpModules. The Global.asax is the ASP.NET equivalent of Global.asa file and it resides in the root directory of an ASP.NET application. At run time, Global.asax is parsed and compiled into a dynamically generated .NET Framework class derived from the HttpApplication base class. The Global.asax file itself is configured so that any direct URL request for it is automatically rejected; external users cannot download or view the code written within it (secured stuff!).
In general, global.asax is responsible for handling higher-level application events such as
called when the application first starts
occurs after _start and is used for initializing code
invoked before destroying an instance of an application
to handle all unhandled exceptions in the application
clean up variables and memory when an application ends (like classic ASP)
used when a client makes a request to any page in the application
after a request for a page has been made, this is the last event that is called
occurs just before ASP.Net begins executing a handler such as a page or a web service. The session state is available at this point.
occurs when the ASP.Net handler finishes execution
occurs when the identity of the current user has been established as valid by the security module
occurs when the user has been authorized to access the resources of the security module
triggered when any new user accesses the web site as with classic ASP
As same in classic ASP, triggered when a user's session times out or ends