.NET Core middleware to generate an Guid and add it to the Request and Response headers
public void ConfigureServices(IServiceCollection services)
{
//...
services.AddGuid();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//...
app.UseGuid();
//...
}
Done!
From now on, everytime the pipeline is run, the request and the response will share an unique Guid under the "X-Guid" header.
The Guid is added to the request as it passes through the middleware and added to the response when the response is starting.