diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Auditing/AbpAspNetCoreAuditingUrlOptions.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Auditing/AbpAspNetCoreAuditingUrlOptions.cs new file mode 100644 index 0000000000..7d371aa331 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Auditing/AbpAspNetCoreAuditingUrlOptions.cs @@ -0,0 +1,10 @@ +namespace Volo.Abp.AspNetCore.Auditing; + +public class AbpAspNetCoreAuditingUrlOptions +{ + public bool IncludeSchema { get; set; } + + public bool IncludeHost { get; set; } + + public bool IncludeQuery { get; set; } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Auditing/AspNetCoreAuditLogContributor.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Auditing/AspNetCoreAuditLogContributor.cs index fc010f9846..f649bb70d8 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Auditing/AspNetCoreAuditLogContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Auditing/AspNetCoreAuditLogContributor.cs @@ -1,9 +1,11 @@ using System; using System.Linq; +using System.Text; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.ExceptionHandling; using Volo.Abp.AspNetCore.WebClientInfo; using Volo.Abp.Auditing; @@ -40,7 +42,7 @@ public class AspNetCoreAuditLogContributor : AuditLogContributor, ITransientDepe if (context.AuditInfo.Url == null) { - context.AuditInfo.Url = BuildUrl(httpContext); + context.AuditInfo.Url = BuildUrl(context, httpContext); } var clientInfoProvider = context.ServiceProvider.GetRequiredService(); @@ -88,10 +90,10 @@ public class AspNetCoreAuditLogContributor : AuditLogContributor, ITransientDepe context.AuditInfo.HttpStatusCode = httpContext.Response.StatusCode; } - protected virtual string BuildUrl(HttpContext httpContext) + protected virtual string BuildUrl(AuditLogContributionContext context, HttpContext httpContext) { - //TODO: Add options to include/exclude query, schema and host - + var options = context.ServiceProvider.GetRequiredService>(); + var stringBuilder = new StringBuilder(); var uriBuilder = new UriBuilder { Scheme = httpContext.Request.Scheme, @@ -99,7 +101,25 @@ public class AspNetCoreAuditLogContributor : AuditLogContributor, ITransientDepe Path = httpContext.Request.Path.ToString(), Query = httpContext.Request.QueryString.ToString() }; - - return uriBuilder.Uri.AbsolutePath; + + if (options.Value.IncludeSchema) + { + stringBuilder.Append(uriBuilder.Scheme); + stringBuilder.Append("://"); + } + + if (options.Value.IncludeHost) + { + stringBuilder.Append(uriBuilder.Host); + } + + stringBuilder.Append(uriBuilder.Path); + + if (options.Value.IncludeQuery) + { + stringBuilder.Append(uriBuilder.Query); + } + + return stringBuilder.ToString(); } }