public class GlobalMiddleware { private readonly RequestDelegate _next; private string _requestBody; public GlobalMiddleware(RequestDelegate next) { _next = next; } public async Task Invoke(HttpContext context) { if (context.Request.Method == "PUT" || context.Request.Method == "POST"|| context.Request.Method == "PATCH") { context.Request.EnableBuffering(); _requestBody = await new StreamReader(context.Request.Body).ReadToEndAsync(); context.Request.Body.Position = 0; } await _next(context); } }