Files
Umbraco-CMS/src/Umbraco.Web/UmbracoApplication.cs
Shannon Deminick c4f1235f0b Fixes issues with ApplicationRegistrar and ApplicationTreeRegistrar during install, they now check if the
application is configured, if not then they exit otherwise exceptions will be logged every time the app starts during install.
Added a log on application end with the reason for shutdown and nicer methods to override in global.asax.
2012-10-11 03:02:23 +05:00

101 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Hosting;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Web.Routing;
using umbraco.businesslogic;
namespace Umbraco.Web
{
/// <summary>
/// The Umbraco global.asax class
/// </summary>
public class UmbracoApplication : System.Web.HttpApplication
{
public UmbracoApplication()
{
_bootManager = new WebBootManager(this);
}
private readonly IBootManager _bootManager;
public static event EventHandler ApplicationStarting;
public static event EventHandler ApplicationStarted;
/// <summary>
/// Initializes the Umbraco application
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_Start(object sender, EventArgs e)
{
//boot up the application
_bootManager
.Initialize()
.Startup(appContext => OnApplicationStarting(sender, e))
.Complete(appContext => OnApplicationStarted(sender, e));
}
/// <summary>
/// Developers can override this method to modify objects on startup
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void OnApplicationStarting(object sender, EventArgs e)
{
if (ApplicationStarting != null)
ApplicationStarting(sender, e);
}
/// <summary>
/// Developers can override this method to do anything they need to do once the application startup routine is completed.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void OnApplicationStarted(object sender, EventArgs e)
{
if (ApplicationStarted != null)
ApplicationStarted(sender, e);
}
/// <summary>
/// A method that can be overridden to invoke code when the application has an error.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void OnApplicationError(object sender, EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
OnApplicationError(sender, e);
}
/// <summary>
/// A method that can be overridden to invoke code when the application shuts down.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void OnApplicationEnd(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
if (SystemUtilities.GetCurrentTrustLevel() == AspNetHostingPermissionLevel.Unrestricted)
{
LogHelper.Info<UmbracoApplication>("Application shutdown. Reason: " + HostingEnvironment.ShutdownReason);
}
OnApplicationEnd(sender, e);
}
}
}