December 2019
Intermediate to advanced
598 pages
12h 21m
English
We can create our own middleware using a class such as the following one. This middleware logs information about every single request that is handled by the ASP.NET Core app:
public class CustomLogger{ private readonly RequestDelegate _next; public CustomLogger(RequestDelegate next) { _next = next ?? throw new ArgumentNullException(nameof(next)); } public async Task Invoke(HttpContext httpContext) { if (httpContext == null) throw new ArgumentNullException(nameof(httpContext)); // TODO - log the request await _next(httpContext); // TODO - log the response }}
This class contains a method called Invoke, which is the code that is executed in the request/response pipeline. The next method to call in the pipeline is passed into ...
Read now
Unlock full access