This is not at all my field of expertise or even near there..., I did however found the question interesting and started some googling and, yes I know, some AI advise.
It seems that your custom middleware for encoding and decoding cookies is correctly implemented
It seems you need to ensure that any headers added during encoding/decoding are included in the outgoing requests.
Make sure that your your Azure Application Gateway is not overly restrictive, and consider adjusting the WAF rules if necessary, I saw the comment that you have no control over this, just check and confirm the status.
To handle 'CustomMiddleware' in .NET, install the necessary packages (AI kicking in, no guarantees given here but help as a pointer in the right direction...) -
dotnet add package Microsoft.AspNetCore.Authentication
dotnet add package Microsoft.AspNetCore.Authentication.Cookies
Rest here copied and pasted using C3... -
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
public class CustomMiddleware
{
private readonly RequestDelegate _next;
public CustomMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
await _next(context);
}
}
Register the middleware in your 'Startup.cs' -
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
public class Startup
{
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseMiddleware<CustomMiddleware>();
}
}
Agian, the code related parts is AI generated, might be completely out of sync on what you want to achieve but help as a pointer...