Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global.asax in Umbraco 6

I had the following in my Global.asax (Umbraco 4.7)

  • Application_Start
  • Application_EndRequest
  • Application_Error
  • Session_Start
  • Session_End

Now I have upgraded to Umbraco 6.0.3, which global.asax inherits from Umbraco.Web.UmbracoApplication

Where do I put my event handlers (and what are the equivalent method names)?

like image 697
Aximili Avatar asked Apr 08 '13 06:04

Aximili


1 Answers

This is what I found so far.

You can create your own class

public class Global : Umbraco.Web.UmbracoApplication
{
  public void Init(HttpApplication application)
  {
    application.PreRequestHandlerExecute += new EventHandler(application_PreRequestHandlerExecute);
    application.EndRequest += (new EventHandler(this.Application_EndRequest));
    //application.Error += new EventHandler(Application_Error); // Overriding this below
  }

  protected override void OnApplicationStarted(object sender, EventArgs e)
  {
    base.OnApplicationStarted(sender, e);
    // Your code here
  }

  private void application_PreRequestHandlerExecute(object sender, EventArgs e)
  {
    try
    {
      if (Session != null && Session.IsNewSession)
      {
        // Your code here
      }
    }
    catch(Exception ex) { }
  }

  private void Application_BeginRequest(object sender, EventArgs e)
  {
    try { UmbracoFunctions.RenderCustomTree(typeof(CustomTree_Manage), "manage"); }
    catch { }
  }

  private void Application_EndRequest(object sender, EventArgs e)
  {
    // Your code here
  }

  protected new void Application_Error(object sender, EventArgs e)
  {
    // Your error handling here
  }
}

And have Global.asax inherit from your class

<%@ Application Codebehind="Global.asax.cs" Inherits="Global" Language="C#" %>

Alternative method: Inherit ApplicationEventHandler - but it's not working for me

like image 120
Aximili Avatar answered Nov 04 '22 11:11

Aximili