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 41 posts 182 karma points
    Mar 01, 2021 @ 19:02
    Filipe Sousa
    0

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

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

    Check here for more info.

  • moraritter 1 post 71 karma points
    Apr 27, 2021 @ 07:03
    moraritter
    0

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

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

    Check here for more info.

    Okay, that makes sense. Thanks for the answers.

  • fincherdavid 2 posts 71 karma points
    Apr 29, 2021 @ 09:57
    fincherdavid
    0

    . I created a clean bare bones project with umbraco 8.2 and put the minimal code in place to apply the action filters and attempt to recreate the same scenario. Thus far I have not been able to. It may be something with the other dependencies that got updated in the upgrade process but I think I can rule out core Umbraco as the issue at this point.

    I will close this issue as not a bug at this point - If I do discover any more about this as to the cause I will comment here in case someone else runs into this in the future.

    Thanks! Looking forward to the new update.

Please Sign in or register to post replies

Write your reply to:

Draft