@manhng

Welcome to my blog!

Global Application Class

October 13, 2020 23:34

Global Application Class (edit)

using System;
using System.Web.Mvc;
using System.Web.Routing;

namespace MyCompany.MyProduct
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
}

protected void Session_Start(object sender, EventArgs e)
{
}

protected void Application_BeginRequest(object sender, EventArgs e)
{
}

protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
}

protected void Application_Error(object sender, EventArgs e)
{
}

protected void Session_End(object sender, EventArgs e)
{
}

protected void Application_End(object sender, EventArgs e)
{
}
}
}

Global.asax.cs

ASP.NET Application Life Cycle Overview for IIS 5.0 and 6.0 | Microsoft Docs

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using System.Web.Security;
using System.Web.SessionState;

namespace WebMvc
{
public class Global : System.Web.HttpApplication
{
/// <summary>
/// Application_Init: Fired when an application initializes or is first called. It is invoked for all HttpApplication object instances.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_Init(object sender, EventArgs e)
{

}

/// <summary>
/// Fired just before an application is destroyed. This is the ideal location for cleaning up previously used resources.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_Disposed(object sender, EventArgs e)
{

}

/// <summary>
/// Fired when the first instance of the HttpApplication class is created. It allows you to create objects that are accessible by all HttpApplication instances.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_Start(object sender, EventArgs e)
{
AppDomain.CurrentDomain.FirstChanceException += (sen, evt) =>
{
Debug.WriteLine(evt.Exception.ToString());
};

AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}



/// <summary>
/// Fired when an application request is received. It is the first event fired for a request, which is often a page request (URL) that a user enters.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_BeginRequest(object sender, EventArgs e)
{

}

/// <summary>
/// The last event fired for an application request.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_EndRequest(object sender, EventArgs e)
{

}

/// <summary>
/// Fired before the ASP.NET page framework begins executing an event handler like a page or Web service.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{

}


/// <summary>
/// Fired when the ASP.NET page framework has finished executing an event handler.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_PostRequestHandlerExecute(object sender, EventArgs e)
{

}

/// <summary>
/// Fired before the ASP.NET page framework sends HTTP headers to a requesting client (browser).
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Applcation_PreSendRequestHeaders(object sender, EventArgs e)
{

}


/// <summary>
/// Fired before the ASP.NET page framework send content to a requesting client (browser).
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_PreSendContent(object sender, EventArgs e)
{

}

/// <summary>
/// Fired when the ASP.NET page framework gets the current state (Session state) related to the current request.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_AcquireRequestState(object sender, EventArgs e)
{

}

/// <summary>
/// Fired when the ASP.NET page framework completes execution of all event handlers. This results in all state modules to save their current state data.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_ReleaseRequestState(object sender, EventArgs e)
{

}

/// <summary>
/// Fired when the ASP.NET page framework completes an authorization request. It allows caching modules to serve the request from the cache, thus bypassing handler execution.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_ResolveRequestCache(object sender, EventArgs e)
{

}

/// <summary>
/// Fired when the ASP.NET page framework completes handler execution to allow caching modules to store responses to be used to handle subsequent requests.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_UpdateRequestCache(object sender, EventArgs e)
{

}

/// <summary>
/// Fired when the security module has established the current user's identity as valid. At this point, the user's credentials have been validated.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{

}

/// <summary>
/// Fired when an unhandled exception is encountered within the application.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
if (ex != null)
{
//log the error
Debug.WriteLine(ex.ToString());
}
}

/// <summary>
/// Fired when a new user visits the application Web site.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Session_Start(object sender, EventArgs e)
{

}

/// <summary>
/// Fired when a user's session times out, ends, or they leave the application Web site.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Session_End(object sender, EventArgs e)
{

}

/// <summary>
/// Fired when the security module has verified that a user can access resources.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_AuthorizeRequest(object sender, EventArgs e)
{

}

/// <summary>
/// Fired when the last instance of an HttpApplication class is destroyed. It is fired only once during an application's lifetime.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_End(object sender, EventArgs e)
{

}
}
}

Categories

Recent posts