mirror of https://github.com/abpframework/abp.git
12 changed files with 1320 additions and 4 deletions
@ -0,0 +1,43 @@ |
|||
using System; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Volo.Abp.Auditing; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Auditing |
|||
{ |
|||
[Dependency(ReplaceServices = true)] |
|||
public class AspNetCoreCorrelationIdProvider : ICorrelationIdProvider, ITransientDependency |
|||
{ |
|||
public const string CorrelationIdKey = "_CorrelationId"; |
|||
|
|||
protected IHttpContextAccessor HttpContextAccessor { get; } |
|||
|
|||
public AspNetCoreCorrelationIdProvider(IHttpContextAccessor httpContextAccessor) |
|||
{ |
|||
HttpContextAccessor = httpContextAccessor; |
|||
} |
|||
|
|||
public virtual string Get() |
|||
{ |
|||
if (HttpContextAccessor.HttpContext?.Request?.Headers == null) |
|||
{ |
|||
return CreateNewCorrelationId(); |
|||
} |
|||
|
|||
string correlationId = HttpContextAccessor.HttpContext.Request.Headers[CorrelationIdKey]; |
|||
|
|||
if (correlationId.IsNullOrEmpty()) |
|||
{ |
|||
correlationId = CreateNewCorrelationId(); |
|||
HttpContextAccessor.HttpContext.Request.Headers[CorrelationIdKey] = correlationId; |
|||
} |
|||
|
|||
return correlationId; |
|||
} |
|||
|
|||
protected virtual string CreateNewCorrelationId() |
|||
{ |
|||
return Guid.NewGuid().ToString("N"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.Auditing |
|||
{ |
|||
public interface ICorrelationIdProvider |
|||
{ |
|||
string Get(); |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Auditing |
|||
{ |
|||
public class NullCorrelationIdProvider : ICorrelationIdProvider, ISingletonDependency |
|||
{ |
|||
public string Get() |
|||
{ |
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,72 @@ |
|||
using System.Reflection.Metadata; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
namespace AuthServer.Host.Migrations |
|||
{ |
|||
public partial class Added_ClientId_And_CorrelationId_To_AuditLogs : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropPrimaryKey( |
|||
"PK_IdentityServerClientPostLogoutRedirectUris", |
|||
"IdentityServerClientPostLogoutRedirectUris" |
|||
); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "PostLogoutRedirectUri", |
|||
table: "IdentityServerClientPostLogoutRedirectUris", |
|||
maxLength: 200, |
|||
nullable: false, |
|||
oldClrType: typeof(string), |
|||
oldMaxLength: 2000); |
|||
|
|||
migrationBuilder.AddPrimaryKey( |
|||
"PK_IdentityServerClientPostLogoutRedirectUris", |
|||
"IdentityServerClientPostLogoutRedirectUris", |
|||
new[] {"ClientId", "PostLogoutRedirectUri"} |
|||
); |
|||
|
|||
migrationBuilder.AddColumn<string>( |
|||
name: "ClientId", |
|||
table: "AbpAuditLogs", |
|||
maxLength: 64, |
|||
nullable: true); |
|||
|
|||
migrationBuilder.AddColumn<string>( |
|||
name: "CorrelationId", |
|||
table: "AbpAuditLogs", |
|||
maxLength: 64, |
|||
nullable: true); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropColumn( |
|||
name: "ClientId", |
|||
table: "AbpAuditLogs"); |
|||
|
|||
migrationBuilder.DropColumn( |
|||
name: "CorrelationId", |
|||
table: "AbpAuditLogs"); |
|||
|
|||
migrationBuilder.DropPrimaryKey( |
|||
"PK_IdentityServerClientPostLogoutRedirectUris", |
|||
"IdentityServerClientPostLogoutRedirectUris" |
|||
); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "PostLogoutRedirectUri", |
|||
table: "IdentityServerClientPostLogoutRedirectUris", |
|||
maxLength: 2000, |
|||
nullable: false, |
|||
oldClrType: typeof(string), |
|||
oldMaxLength: 200); |
|||
|
|||
migrationBuilder.AddPrimaryKey( |
|||
"PK_IdentityServerClientPostLogoutRedirectUris", |
|||
"IdentityServerClientPostLogoutRedirectUris", |
|||
new[] { "ClientId", "PostLogoutRedirectUri" } |
|||
); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue