Copied to clipboard

Flag this post as spam?

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


  • kapil 21 posts 114 karma points
    May 01, 2019 @ 20:40
    kapil
    0

    how to register mvc Exception filter using Composing in Umbraco 8

    Hi,

    I want to register Custom Exception filter using Composer in Umbraco 8. Help on this is greatly appreciate.

      public class Global : UmbracoApplication, IComposer
        {
            public void Compose(Composition composition)
            {
                  // want to register custom exception filter here
            }
        }
    

    Custom filter

    public class MyExceptionFilter : FilterAttribute, IExceptionFilter
        {
            public void OnException(ExceptionContext exceptionContext)
            {
                if (!exceptionContext.ExceptionHandled && exceptionContext.Exception is NullReferenceException)
                {
                    exceptionContext.Result = new RedirectResult("Error.html");
                    exceptionContext.ExceptionHandled = true;
                }
                else
                {
                    var exceptionDetails = new
                    {
                        ApplicationName = Constants.FirstAgencyWeb,
                        Controller = exceptionContext.RouteData.Values["controller"],
                        Action = exceptionContext.RouteData.Values["action"],
                        ErrorMessage = exceptionContext.Exception.InnerException,
                        ErrorStackTrace = exceptionContext.Exception.StackTrace
                    };
                    Log.Logger.Error("Error {@Detials}", exceptionDetails);
                }
            }
        }
    
  • Filipe Sousa 43 posts 205 karma points
    Mar 01, 2021 @ 19:02
    Filipe Sousa
    1

    A bit late but maybe this can help somebody else. Try

    GlobalConfiguration.Configuration.Filters.Add(
    new MyExceptionFilter() );
    

    Check here for more info.

  • 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