Posted inTechnology / ASP.NET

Global.asax File in ASP.NET MVC Tutorial with Example

Global.asax File in ASP.NET MVC Tutorial with Example

Today, We want to share with you Global.asax File in ASP.NET MVC Tutorial with Example.In this post we will show you ASP.NET Global.asax file Example, hear for Exploring the Global.asax file in ASP.NET we will give you demo and example for implement.In this post, we will learn about Setting Up Global Objects with the global.asax File with an example.

Use of Global.asax in Asp.net

Introduction to Global.asax in Asp.net

What is the use of Global.asax file events in asp.net?

In this post, I will explain about the various event that is raised during the life cycle of a web application. Global.asax in Asp.net is used to specify an event handler for some application level event.

Global.asax Syntax

The Global.asax file is optional.

Global.asax in Asp.net handle any application or some times session events

Application_Init: This event Fires each time application initializes or is first called. It is invoked for all HttpApplication object instances.

Application_Disposed: This event Fires just before an application is destroyed. This is the suitable location for cleaning up any previously used resources.

Application_Error: This event Fires when an unhandled exception is encountered within the web application.So using this event we can write generic exception handler.

Application_Start: This event is raised when the application first starts up and the application domain is created. This event suitable for to set the rule that remains same till application runs.Ex, Routing rule, navigation tree etc.

Application_End: This event raised just before when web application ends.

Application_BeginRequest: This event is raised at the start of every request within the web application.

Application_EndRequest: This event is raised at the end of the web request and just before the objects are released and reclaimed. As a result, It’s a suitable event for cleanup code.

Application_PreRequestHandlerExecute: This event is raised before the ASP.NET page framework begins executing an event handler like a page or Web service.

Application_PostRequestHandlerExecute: This event is raised when the event handler finish the execution

Applcation_PreSendRequestHeaders: This event is raised when .net framework send the web HTTP header to a respected requesting client(i.e. Browser)

Application_PreSendContent: This event is raised before the ASP.NET page framework sends content to a requesting client (browser).

Application_AcquireRequestState: This event is raised when .net framework gets the current state of the current web request.

Application_ReleaseRequestState: This event is raised when the ASP.NET page framework completes execution of all event handlers. This results in all state modules to save their current state data.

Application_ResolveRequestCache: This event is raised when the ASP.NET web page framework completes the process of an authorization request.

Application_UpdateRequestCache: This event is raised when the ASP.NET page framework completes handler execution

Application_AuthenticateRequest: This event is raised when the security module has established the current user’s identity as valid. At this point, the user’s credentials have been validated.

Application_AuthorizeRequest: This event is raised when the security module has verified that a user can access resources.

Session_Start: This event is raised when a new user visits the application Web site.

Session_End: This event is raised when a user’s session times out, ends, or they leave the application Web site.

Example Global.asax implementation: C#





    static string _pagePath;

    void Application_Start(object sender, EventArgs e)
    {
        // source Code that simple ASP.net Global runs on application just startup
        _pagePath = Server.MapPath("~/Folder/Page.aspx");
    }

    // ...


Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about ASP.NET Global.asax File Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype