Skip to content

Instantly share code, notes, and snippets.

@uzbekdev1
Created October 6, 2025 09:37
Show Gist options
  • Save uzbekdev1/8a0699f4f65f303f7961a6d03e26ea7f to your computer and use it in GitHub Desktop.
Save uzbekdev1/8a0699f4f65f303f7961a6d03e26ea7f to your computer and use it in GitHub Desktop.

Revisions

  1. uzbekdev1 revised this gist Oct 6, 2025. 1 changed file with 17 additions and 38 deletions.
    55 changes: 17 additions & 38 deletions GlobalMiddleware.cs
    Original file line number Diff line number Diff line change
    @@ -1,46 +1,25 @@
    using AppEnvironment;
    using BusinessLogic.Core;
    using ClientApi.Consts;
    using ClientApi.Core;
    using ClientApi.Helpers;
    using DataAccess.Helpers;
    using DataAccess.Services;
    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.Http.Extensions;
    using Microsoft.Extensions.Logging;
    using System;
    using System.IO;
    using System.Linq;
    using System.Net.Http;
    using System.Security.Claims;
    using System.Text;
    using System.Threading.Tasks;

    namespace ClientApi.Middlewares
    public class GlobalMiddleware
    {
    public class GlobalMiddleware
    {

    private readonly RequestDelegate _next;
    private string _requestBody;

    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;
    }
    public GlobalMiddleware(RequestDelegate next)
    {
    _next = next;
    }

    await _next(context);
    }
    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);
    }

    }
  2. uzbekdev1 created this gist Oct 6, 2025.
    46 changes: 46 additions & 0 deletions GlobalMiddleware.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    using AppEnvironment;
    using BusinessLogic.Core;
    using ClientApi.Consts;
    using ClientApi.Core;
    using ClientApi.Helpers;
    using DataAccess.Helpers;
    using DataAccess.Services;
    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.Http.Extensions;
    using Microsoft.Extensions.Logging;
    using System;
    using System.IO;
    using System.Linq;
    using System.Net.Http;
    using System.Security.Claims;
    using System.Text;
    using System.Threading.Tasks;

    namespace ClientApi.Middlewares
    {
    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);
    }

    }
    }