Julian Gonzalez

Generation

generate functionThu, 04 May 2023

example create middleware in web api .Net 6 and show register in Program.cs and use from controller

public class LoggingMiddleware { private readonly RequestDelegate _next; public LoggingMiddleware(RequestDelegate next) { _next = next; } public async Task Invoke(HttpContext context, ILogger<LoggingMiddleware> logger) { logger.LogInformation("Handling request: " + context.Request.Path); await _next(context); logger.LogInformation("Finished handling request."); } }

Questions about programming?Chat with your personal AI assistant