Monday, April 11, 2011

Global.asax file in Asp.Net

Global.asax file comes in ASP.NET from ASP language. This file contains events for Application and Session, and global.asax must be in the root directory of .net web application.
Below is the list of events in global.asax file you can call.

Application events in global.asax:

 

Application_Start:
This event used to set up an application environment and called only when the application starts first time.

Application_Init:
This method occurs after Application_Start and is used for initializing your code.

Application_Disposed:
This event occurs before destroying an instance of an application.

Application_Error:
This event is used to handle all unhandled exceptions in the application. It's the best place to put your error tracking mechanism.

Application_End:
Like classic ASP method it used to clean up variables and memory while application ends.

Application_BeginRequest:
This event occurs when a client makes a request to any pages of the application. It can be useful for example to open connection to database for all request.

Application_EndRequest:
This is the last request to the page.

Application_PreRequestHandlerExecute:
This event occurs before ASP.Net begins executing a handler such as a page or a web service. At this point, the session state is available.

Application_PostRequestHandlerExecute:
This method occurs when the ASP.Net handler finishes execution.

Application_PreSendRequestHeaders:
This event occurs just before ASP.Net sends HTTP Headers to the client. You can use it if you want to modify a header

Application_PreSendRequestContent:
This event occurs just before sending content to the client.

Application_AcquireRequestState:
This event occurs when ASP.Net acquires the current state (eg. Session state) associated with the current request.

Application_ReleaseRequestState:
This event occurs after ASP.NET finishes executing all request handlers and causes state modules to save the current state data.

Application_AuthenticateRequest:
This event occurs when the identity of the current user has been established as valid by the security module .

Application_AuthorizeRequest:
This event occurs when the user has been authorized to access the resources of the security module .

Session events in global.asax:

Session_Start:
As with classic ASP, this event is triggered when any new user accesses the web site.

Session_End:
As with classic ASP, this event is triggered when a user's session times out or ends. The default session timeout is 20 min.

No comments:

Post a Comment

Ajax CalendarExtender displaying at wrong position in Chrome

< script type ="text/javascript" language ="javascript">     function onCalendarShown(sender, args)...