Copied to clipboard

Flag this post as spam?

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


  • Aximili 177 posts 278 karma points
    Apr 08, 2013 @ 08:45
    Aximili
    0

    Global.asax replacement 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 for each)?

    Thanks in advance!

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Apr 08, 2013 @ 09:18
    Jeroen Breuer
    3

    You can find more info here: http://our.umbraco.org/Documentation/Reference/Events/application-startup

    You could also create a new Global.cs and let Umbraco inherit from that. Here is an example:

    Global.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace Umbraco.Extensions.Utilities
    {
        public class Global : Umbraco.Web.UmbracoApplication
        {
            public override string GetVaryByCustomString(HttpContext context, string custom)
            {
                if (custom.ToLower() == "url")
                {
                    return "url=" + context.Request.Url.AbsoluteUri;
                }
    
                return base.GetVaryByCustomString(context, custom);
            }
        }
    }

    Global.asax from Umbraco

    <%@ Application Codebehind="Global.asax.cs" Inherits="Umbraco.Extensions.Utilities.Global" Language="C#" %>
    Jeroen
  • Aximili 177 posts 278 karma points
    Apr 08, 2013 @ 09:30
    Aximili
    0

    Hi Jeroen, thank you for your quick reply.

    I have looked into IApplicationEventHandler (since I'm using Umbraco 6.0.3) and extending Umbraco.Web.UmbracoApplication.

    However my problem remains: Which one do I use and what methods can I use to replace:

    • Application_Start
    • Application_EndRequest
    • Application_Error
    • Session_Start
    • Session_End

    I couldn't find all 5 of them on either of those class, and implementing IApplicationEventHandler gives me this error:

    Values cannot be returned until Resolution is frozen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Apr 08, 2013 @ 09:33
    Jeroen Breuer
    0

    If you want to replace those values (which you don't have too if you only want to use events) I think it's best to override the Global.asax like I did in my example.

    Jeroen

  • Aximili 177 posts 278 karma points
    Apr 08, 2013 @ 09:45
    Aximili
    0

    That's cool, except I only found EndRequest and Error, and this is my class now

    public class Global : Umbraco.Web.UmbracoApplication
    {
      public void Init(HttpApplication application)
      {
          application.EndRequest += (new EventHandler(this.Application_EndRequest));
          application.Error += new EventHandler(Application_Error);
      }
       
      private void Application_EndRequest(object sender, EventArgs e)
      {
          // My code
      }
       
      private void Application_Error(object sender, EventArgs e)
      {
          // My code
      }
    }

    Do you know what are the equivalent for:

    • Application_Start
    • Session_Start
    • Session_End

     

  • Soeren Sprogoe 575 posts 259 karma points
    May 13, 2013 @ 16:10
    Soeren Sprogoe
    0

    Listening, as I've run into the exact same problem now.

    The document that Jeroen points to has examples on all v4.x of Umbraco, plus v6.1. Which is strange, since 6.1 looks like a future version. And it doesn't seem like it is a typo (fx. should have read 6.0.1) as, just as Hardi states, I can't find anything equivalent to Application_Start.

    /Soeren

  • Aximili 177 posts 278 karma points
    May 15, 2013 @ 06:59
    Aximili
    0

    I'm also still waiting for an answer.

    You can override OnApplicationStarted but I couldn't use it (Request is unavailable yet at that point)

      protected override void OnApplicationStarted(object sender, EventArgs e)
      {
      }

    The closest I could find so far is this

    application.PreRequestHandlerExecute += new EventHandler(application_PreRequestHandlerExecute);
  • Soeren Sprogoe 575 posts 259 karma points
    May 15, 2013 @ 10:51
    Soeren Sprogoe
    0

    Looks like I've got the following working with v6.0.5:

    using Umbraco.Core;
    using Umbraco.Web;
    using umbraco.BusinessLogic; namespace MySite { public class EventHandlers : Umbraco.Core.IApplicationEventHandler { public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { } public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { } public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { Log.Add(LogTypes.Custom, -1, "BaZinga!"); } } }
  • Edwin van Koppen 156 posts 270 karma points
    May 09, 2014 @ 17:22
    Edwin van Koppen
    0

    Somebody knows how to use Application_Error in the IApplicationEventHandler? Or how do i catch a http 400 error?

  • Davide 9 posts 29 karma points
    Jan 22, 2015 @ 08:41
    Davide
    0

    Hi all, 

    I was using the URL rewriting in UMBRACO 4.7.2 on my custom Global.asax file into the Application_BeginRequest method. Now I'm trying to upgrade to version 6.0.0 where I saw that I have to change my custom Global.asax to inherit from Umbraco.Web.UmbracoApplication.

    No problems so far in general in the application, but when the global.asax triggers the HttpContext.Current.RewritePath(URL), after migrating to version 6, the method does not rewrite the URL at all. It does not give any error or exception, it simply doesn't rewrite the URL, and consequently the system returns 404 , file not found.

    Any ideas about it? Did the version 6 of Umbraco stop to support the HttpContext.Current.RewritePath method in its new Global.asax?

    Thanks in advance to all of you!

  • Ihor 11 posts 83 karma points
    Dec 12, 2016 @ 16:45
    Ihor
    0

    Hi All,

    I have the same problem with version 6.2.6.

    Did anyone find the way how to solve it?

    Thanks Ihor

Please Sign in or register to post replies

Write your reply to:

Draft