C
C#2y 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
});
}
}
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)));
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.
2 Replies
pox
pox2y ago
Check if you can find action or something inside context
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server