Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rasmus Trumf 73 posts 134 karma points
    17 days ago
    Rasmus Trumf
    0

    Using Global.asax and/or Composers in U8

    Hi

    I'm converting from U7 V7.15.4 to U8 V8.10.0

    I have created a component to replace ApplicationOnStart but i'm a little puzzled about what to so with the other events in ApplicationEventHandler ie: ApplicationBeginRequest, Session_Start and OnApplicationError (that i'm overriding in V7)

    Should I keep global.asax for that or add some event listeners in a component? Probably something like:

    public class ApplicationComposer : ComponentComposer<ApplicationComponent>, IUserComposer
    {
      public override void Compose(Composition composition)
      {
        composition.Register<IErrorLogService, ErrorLogService>(Lifetime.Scope);
        base.Compose(composition);
      }
    }
    
    public class ApplicationComponent : IComponent
    {
      private readonly IErrorLogService _errorLogService;
    
      public ApplicationComponent(IErrorLogService errorLogService)
      {
        _errorLogService = errorLogService;
      }
    
      public void Initialize()
      {
        //How do I get the ApplicationEventHandler in Umbraco???
    
        Umbraco.Core.Application.BeginRequest += Application_BeginRequest;
        Umbraco.Core.Session.Start += Session_Start;
        Umbraco.Core.OnApplicationError += OnApplicationError;
    
        //code that originally was in Application_OnStart here
        //...
      }
    
      public void Terminate()
      { 
      }
    }
    
    private void Application_BeginRequest(Object source, EventArgs e)
    {
    }
    
    private void Session_Start(object sender, EventArgs e)
    {
    }
    
    private override void OnApplicationError(object sender, EventArgs e)
    {
      base.OnApplicationError(sender, e);
    }
    

    I hope it makes sense and that somebody can help Thanks

  • Marc Goodson 1390 posts 9427 karma points MVP 5x c-trib
    1 week ago
    Marc Goodson
    0

    Hi Rasmus

    My hunch here is you could handle the UmbracoApplicationBase ApplicationInit event

    see this approach in the core:

    https://github.com/umbraco/Umbraco-CMS/blob/f288a6334277ef1c3b439c16d94b5ed7df36fb54/src/Umbraco.Web/Logging/WebProfilerComponent.cs#L9

    This event would give you access to the underlying HttpApplication app, from which I reckon you could bind to the Begin Request?

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft