Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access ActionArguments in IExceptionFilter

Is it possible to access ActionArguments in an IExceptionFilter?

enter image description here

According to the above picutre Exception Filters run after Action Filters which have access to them. So I don't see why they can't.

In an ActionFilter you access it like this

public class MyFilter : IActionFilter
{
    public void OnActionExecuting(ActionExecutingContext context)
    {
        context.ActionArguments // I need access to this in order to find out what type the input argument(s) was.
    }
}

But an IExceptionFilter uses public void OnException(ExceptionContext context) instead.

like image 916
Snæbjørn Avatar asked May 04 '26 05:05

Snæbjørn


1 Answers

I figured it out :)

public class ExceptionFilter : IExceptionFilter, IActionFilter
{
    private IDictionary<string, object> _actionArguments;

    public void OnException(ExceptionContext context)
    {
        _actionArguments // great success!
    }

    public void OnActionExecuting(ActionExecutingContext context)
    {
        _actionArguments = context.ActionArguments;
    }

    public void OnActionExecuted(ActionExecutedContext context)
    {
        // do nothing
    }
}
like image 116
Snæbjørn Avatar answered May 05 '26 20:05

Snæbjørn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!