|
|
@ -1,4 +1,5 @@ |
|
|
using System; |
|
|
using System; |
|
|
|
|
|
using System.Collections.Generic; |
|
|
using Microsoft.AspNetCore.Http; |
|
|
using Microsoft.AspNetCore.Http; |
|
|
using Microsoft.Extensions.Options; |
|
|
using Microsoft.Extensions.Options; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
@ -21,9 +22,24 @@ public class AbpCorrelationIdMiddleware : IMiddleware, ITransientDependency |
|
|
|
|
|
|
|
|
public async Task InvokeAsync(HttpContext context, RequestDelegate next) |
|
|
public async Task InvokeAsync(HttpContext context, RequestDelegate next) |
|
|
{ |
|
|
{ |
|
|
var correlationId = _correlationIdProvider.Get(); |
|
|
var correlationId = GetCorrelationIdFromRequest(context); |
|
|
CheckAndSetCorrelationIdOnResponse(context, _options, correlationId); |
|
|
using (_correlationIdProvider.Change(correlationId)) |
|
|
await next(context); |
|
|
{ |
|
|
|
|
|
CheckAndSetCorrelationIdOnResponse(context, _options, correlationId); |
|
|
|
|
|
await next(context); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected virtual string? GetCorrelationIdFromRequest(HttpContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
var correlationId = context.Request.Headers[_options.HttpHeaderName]; |
|
|
|
|
|
if (correlationId.IsNullOrEmpty()) |
|
|
|
|
|
{ |
|
|
|
|
|
correlationId = Guid.NewGuid().ToString("N"); |
|
|
|
|
|
context.Request.Headers[_options.HttpHeaderName] = correlationId; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return correlationId; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected virtual void CheckAndSetCorrelationIdOnResponse( |
|
|
protected virtual void CheckAndSetCorrelationIdOnResponse( |
|
|
|