ASP.NET Core controller level exception handling

To handle exceptions on Controller/Action level Exception Filters are used.

[TypeFilter(typeof(SampleExceptionFilter))]
public class ExceptionController : Controller

Exception Filters are implemented using IExceptionFilter with OnExcetion method override to handle exceptions.

Exception Filters can be applied to Controller and Action level.

Further read:

https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/filters?view=aspnetcore-6.0#exception-filters

https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.filters.iexceptionfilter?view=aspnetcore-6.0

Leave a Reply

Your email address will not be published. Required fields are marked *

Solve : *
6 + 30 =