JPReddy
JPReddy

Reputation: 65523

Audit.net ignoring Http Get methods with a global action filter

I'm using Audit.net for auditing all .net core Web API requests. I want to use global action filter to audit all the HTTP requests but don't want to Audit HTTP GET methods. While configuring AddAuditFilter I can conditionally log action by using LogActionIf filter but unable to set the condition to check whether this action is related to Http Get. Any idea how to add conditional filter? I'm referring to below configuration:

mvc.AddAuditFilter(config => config
                .LogActionIf(d => d.ControllerName == "Orders" && d.ActionName != "GetOrder")
                .WithEventType("{verb}.{controller}.{action}")
                .IncludeHeaders(ctx => !ctx.ModelState.IsValid)
                .IncludeRequestBody()
                .IncludeModelState()
                .IncludeResponseBody(ctx => ctx.HttpContext.Response.StatusCode == 200));

Upvotes: 2

Views: 660

Answers (1)

thepirat000
thepirat000

Reputation: 13114

What about using LogRequestIf which takes an HttpRequest as parameter:

mvc.AddAuditFilter(config => config
    .LogRequestIf(r => r.Method != "GET")  // <-- This
    .WithEventType("{verb}.{controller}.{action}")
    .IncludeHeaders(ctx => !ctx.ModelState.IsValid)
    .IncludeRequestBody()
    .IncludeModelState()
    .IncludeResponseBody(ctx => ctx.HttpContext.Response.StatusCode == 200));

Upvotes: 3

Related Questions