Disable audit logging for Get requests by default.

pull/395/head
Halil ibrahim Kalkan 7 years ago
parent 6492fdd158
commit 00a0fce9e3

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using Volo.Abp.Auditing;
@ -29,7 +30,7 @@ namespace Volo.Abp.AspNetCore.Auditing
public async Task Invoke(HttpContext httpContext)
{
if (!ShouldWriteAuditLog())
if (!ShouldWriteAuditLog(httpContext))
{
await _next(httpContext);
return;
@ -48,7 +49,7 @@ namespace Volo.Abp.AspNetCore.Auditing
}
}
private bool ShouldWriteAuditLog()
private bool ShouldWriteAuditLog(HttpContext httpContext)
{
if (!Options.IsEnabled)
{
@ -60,6 +61,12 @@ namespace Volo.Abp.AspNetCore.Auditing
return false;
}
if (!Options.IsEnabledForGetRequests &&
string.Equals(httpContext.Request.Method, HttpMethods.Get, StringComparison.OrdinalIgnoreCase))
{
return false;
}
return true;
}
}

@ -24,6 +24,12 @@ namespace Volo.Abp.Auditing
public List<Type> IgnoredTypes { get; }
public IEntityHistorySelectorList EntityHistorySelectors { get; }
//TODO: Move this to asp.net core layer or convert it to a more dynamic strategy?
/// <summary>
/// Default: false.
/// </summary>
public bool IsEnabledForGetRequests { get; set; }
public AbpAuditingOptions()
{

Loading…
Cancel
Save