C#C
C#3y ago
M B V R K

❔ How to disable an Exception Filter for a specific Action in ASP.NET Core?

Hi dear friends, I hope you doing well,
I'm working on an ASP.NET Core 7 project.
I created the following Exception Filter:
public class MyExceptionFilter : IExceptionFilter
{
    public void OnException(ExceptionContext context)
    {
        context.Result = new JsonResult(new
        {
            context.Exception.Message,
            context.Exception.StackTrace
        });
    }
}


The following is its registration in Program.cs:
services.AddControllers(options => options.Filters.Add(typeof(MyExceptionFilter)));


In a Controller I have an Action called GetBranches and I want to disable that Filter for it.
Please how do I can disable it ?

Massive thanks in advance.
Was this page helpful?