Copied to clipboard

Flag this post as spam?

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


  • Haansi 51 posts 150 karma points
    Dec 05, 2014 @ 06:01
    Haansi
    0

    umbracoApplication.Error not firing if exception accure in MVC ?

    If my understanding is correct with Umbraco 7 we can't have global.asax file. I have to handle asp.net's application error event and log errors. I follow this link and hock umbracoApplication.Error event.

    Issue is, on error this event is not firing. When I run application I can see umbracoApplication.Error is regestered but throwing an error in MVC action do not come here. Please help me.

    My MVCStartup.cs is below:

     public class MyStartupHandler : IApplicationEventHandler
    {
        public void OnApplicationStarted(
            UmbracoApplicationBase umbracoApplication,
            ApplicationContext applicationContext)
        {
            //Create a custom route
            RouteTable.Routes.MapRoute(
                "HealthInsurance",
                "HealthInsurance/{action}/{id}",
                new
                {
                    controller = "HealthInsurance",                    
                    id = UrlParameter.Optional
                });
    
            RouteTable.Routes.MapRoute(
              "HomeLoan",
              "HomeLoan/{action}/{id}",
              new
              {
                  controller = "HomeLoan",                  
                  id = UrlParameter.Optional
              });
    
            RouteTable.Routes.MapRoute(
              "LifeInsurance",
              "LifeInsurance/{action}/{id}",
              new
              {
                  controller = "LifeInsurance",
                  action = "Index",
                  id = UrlParameter.Optional
              });
    
            RouteTable.Routes.MapRoute(
             "EDM",
             "EDM/{action}/{id}",
             new
             {
                 controller = "EDM",
                 action = "Index",
                 id = UrlParameter.Optional
             });
    
            RouteTable.Routes.MapRoute(
           "AFFILIATE",
           "AFFILIATE/{action}/{id}",
           new
           {
               controller = "AFFILIATE",
               action = "Index",
               id = UrlParameter.Optional
           });        
    
    
            RouteTable.Routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new
            {
               // controller = "Home",
                action = "Index",
                id = UrlParameter.Optional
            }
        );
        }
    
        void umbracoApplication_Error(object sender, System.EventArgs e)
        {
            throw new Exception("Test MVc Umbraco Error");
        }
        public void OnApplicationInitialized(
            UmbracoApplicationBase umbracoApplication,
            ApplicationContext applicationContext)
        {
        }
        public void OnApplicationStarting(
            UmbracoApplicationBase umbracoApplication,
            ApplicationContext applicationContext)
        {
            umbracoApplication.Error += umbracoApplication_Error;
        }
    }
    
    1. My Global.asax file has only below line but no Codebehind class is there.

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

    2. Controller & Action is below:

    public class LandingController : Umbraco.Web.Mvc.RenderMvcController
    {       
        [OutputCache(Duration=300)]
        public ActionResult uLanding(Landing model)
        {
            throw new Exception();
            return base.Index(model);
        }
    
    }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies