Modify middleware response
.NET Core 3+ solution with proper resource handling: Replace response stream by MemoryStream to prevent its sending. Return the original stream after the response is modified: public async Task Invoke(HttpContext context) { var response = context.Response; //uncomment this line to re-read context.Request.Body stream //context.Request.EnableBuffering(); var originBody = response.Body; using var newBody = new MemoryStream(); response.Body … Read more