August 2017
Intermediate to advanced
330 pages
7h 26m
English
In ASP.NET Core, exceptions can be handled in two ways: by UseExceptionHandler middleware or writing our own exception handler using the IExceptionFilter interface.
We will write a custom exception handler using the IExceptionFilter interface, register it globally in MVC services, and test it.
Create the PacktExceptionFilter class and implement the IExceptionFilter interface and the OnException method. This filter reads the exception and prepares to send it to the client, as follows:
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Filters; using System; using System.Net; namespace filters_demo { // Exception Filter example public class PacktExceptionFilter : IExceptionFilter { public void OnException(ExceptionContext ...Read now
Unlock full access