Background: ASP.NET 5 (ASP.NET Core 1.0) MVC 6 application using Dapper and the Repository Pattern
Obviously, like with every other website/app, I'm trying to eliminate most/all of the exceptions that popup in my website.
I implemented an ExceptionFilter in order to catch all unhandled exceptions like this:
public class UnhandledExceptionFilter : ActionFilterAttribute, IExceptionFilter
{
private readonly IErrorRepo _errorRepo;
public UnhandledExceptionFilter(IErrorRepo errorRepo)
{
_errorRepo = errorRepo;
}
public void OnException(ExceptionContext context)
{
try
{
_errorRepo.SaveException(context.Exception);
}
catch { }
}
}
This works great when the error comes from C# code. But I've purposely put in errors in my razor views (cshtml files) and those are NOT getting caught by this filter.
Is there an additional attribute/interface that I need to inherit in order to catch razor exceptions?
UPDATE:
Here's where the filter attribute is specified, in the startup.cs file in the ConfigureServices method.
services.AddMvc(options =>
{
options.Filters.Add(new UnhandledExceptionFilter(new ErrorRepo(Configuration)));
});