What is the goal of global.asax in asp.net

How can we use global.asax in asp.net? So what is this?

+54
Feb 26 '10 at 9:30
source share
6 answers

MSDN has a global.asax file target outline.

Effectively, global.asax allows you to write code that runs in response to "system level" events, such as application launch, session termination, application error that occurs, without having to try and train this code on every page of your site.

You can use it by choosing Add> Create Element> Global Application Class in Visual Studio. After adding the file, you can add code under any of the events that are listed (and created by default, at least in Visual Studio 2008):

  • Application_Start
  • Application_End
  • Session_start
  • Session_end
  • Application_BeginRequest
  • Application_AuthenticateRequest
  • Application_Error

There are other events that you can also connect to, such as "LogRequest".

+64
Feb 26 '10 at 9:34 on
source share

Global Asax Events Explained

Application_Init: Called when the application is initialized or called first. It is called for all instances of the HttpApplication object.

Application_Disposed: Fired immediately before destroying the application. It is an ideal place to clean previously used resources.

Application_Error: Raised when an unhandled exception is thrown in the application.

Application_Start: Called when the first instance of the HttpApplication class is created. It allows you to create objects that are accessible to all instances of HttpApplication.

Application_End: Called when the last instance of the HttpApplication class is destroyed. It only starts once during the life of the application.

Application_BeginRequest: Called when an application request is received. This is the first event that fires for a request, which is often a page request (URL) that a user enters.

Application_EndRequest: The last event fired to request an application.

Application_PreRequestHandlerExecute: Fired before the ASP.NET page structure begins to execute an event handler, such as a page or web service.

Application_PostRequestHandlerExecute: Invoked when the ASP.NET page structure is completed executing an event handler.

Applcation_PreSendRequestHeaders: Fired before the ASP.NET page structure sends HTTP headers to the requesting client (browser).

Application_PreSendContent: Fired before the ASP.NET page structure sends content to the requesting client (browser).

Application_AcquireRequestState: Called when the ASP.NET page structure receives the current state (session state) associated with the current request.

Application_ReleaseRequestState: Called when the ASP.NET page structure completes the execution of all event handlers. This leads to the fact that all state modules retain their current state data.

Application_ResolveRequestCache: Called when the ASP.NET page structure completes the authorization request. It allows you to cache modules for servicing a request from the cache, thereby bypassing the execution of the handler.

Application_UpdateRequestCache: Called when the ASP.NET page structure completes the execution of the handler to allow caching modules to store responses that will be used to process subsequent requests.

Application_AuthenticateRequest: Called when the security module has set the current username to be valid. At this point, the user credentials have been verified.

Application_AuthorizeRequest: Fired when the security module confirms that the user can access resources.

Session_Start: Called when a new user visits the application’s website.

Session_End: Dismissal when a user session ends, ends, or leaves the application website.

+38
Nov 11 '14 at 5:34
source share

The Global.asax file, also known as the ASP.NET application file, is an additional file containing code for responding to application level and session-level events raised by ASP.NET or through HTTP modules.

http://msdn.microsoft.com/en-us/library/2027ewzw.aspx

+8
Feb 26 '10 at 9:34 on
source share

Global.asax is an asp.net application file.

This is an optional file that processes events generated by ASP.NET or HttpModules. It is mainly used for applications and event start / end sessions and for handling global errors.

When used, it should be at the root of the site.

+5
Feb 26 '10 at 9:34 on
source share

Global.asax can be used to handle events that arise from the application. This link gives a good explanation: http://aspalliance.com/1114

+1
Feb 26 '10 at 9:33
source share

The root folder of the web application is of particular importance, and certain content may be present in this folder. It may have a special file called "Global.asax". The ASP.Net framework uses content in global.asax and creates a class at runtime that inherits from HttpApplication. ASP.NET maintains a pool of HttpApplication instances retrieved from Global.asax for the duration of the application. when an application receives an HTTP request, the ASP.Net page structure designates one of these instances to process this request. This instance is responsible for managing the lifetime of the request to which it is assigned, and the instance can only be reused after the request is completed when it is returned to the pool. The instance members in Global.asax cannot be used to exchange data on requests, but there can be a static member. Global.asax may contain event handlers for the HttpApplication object and some other important methods that will be executed at various points in the web application.

0
Nov 08 '16 at 4:53 on
source share



All Articles