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 78 posts 160 karma points
    Jan 03, 2021 @ 15:13
    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 2141 posts 14344 karma points MVP 8x c-trib
    Jan 08, 2021 @ 22:14
    Marc Goodson
    101

    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

  • Rasmus Trumf 78 posts 160 karma points
    Jan 27, 2021 @ 08:37
    Rasmus Trumf
    0

    Hi Marc

    Sorry for my late response. I implemented too many things without being able to compile and suddenly i just couldn't find my way in all the errors... I had to start over and manually created all data and document types so now i have a working copy of U8 ;-)

    Anyway this worked - at least for BeginRequest and Error. Still looking for at way to catch the Session_Start event.

    Thanks

  • Rasmus Trumf 78 posts 160 karma points
    Jan 27, 2021 @ 10:05
    Rasmus Trumf
    1

    I managed to hook up on the Session_Start event also.

    https://www.goatly.net/post/hooking-into-session-start-events-in-an-http-module/

    Everything is great.

    Thanks again Marc :)

Please Sign in or register to post replies

Write your reply to:

Draft