简体   繁体   English

Audit.Net 的响应标头中缺少位置 header

[英]Location header missing in response headers in Audit.Net

When using Audit.Net I'm including entire response to be audited such as response content, headers and IncludeHeaders too, below is my configuration:使用 Audit.Net 时,我也包括要审核的整个响应,例如响应内容、标头和 IncludeHeaders,以下是我的配置:

mvcOptions.AddAuditFilter(a => a
            .LogRequestIf(d => d.HttpContext.Request.Method != HttpMethods.Get)
            .WithEventType("{verb}.{controller}.{action}")
            .IncludeHeaders()
            .IncludeResponseBody()
            .IncludeResponseHeaders()); 

But I'm able to see only below response headers.但我只能看到下面的响应标题。

"Headers": {
      "Connection": "keep-alive",
      "Content-Type": "application/json",
      "Accept": "*/*",
      "Accept-Encoding": "gzip, deflate, br",
      "Host": "localhost:50266",
      "User-Agent": "PostmanRuntime/7.26.10",
      "Content-Length": "3503",
      "Postman-Token": "645b83e3-d1b6-40f8-b615-85052b614b37"
    },
    "ResponseHeaders": {
      "Request-Context": "appId=xxxxxxx",
      "Referrer-Policy": "no-referrer",
      "X-Content-Type-Options": "nosniff",
      "Content-Security-Policy": "default-src 'self';"
    }

My response also contains Location header but the same is not visible in the audit log.我的回复还包含位置 header 但在审核日志中不可见。 This request was raised through Postman and the response headers in postman can be seen below:此请求是通过 Postman 提出的,postman 中的响应标头如下所示:

在此处输入图像描述

Location header is clearly visible in postman, but the same is missing in audit log, what did I miss here?位置 header 在 postman 中清晰可见,但在审计日志中也缺少相同的内容,我在这里错过了什么? Any pointers please?请问有什么指点吗?

You should use the provided middleware in order to get the response headers, since most of the response headers are added on Result Filters which executes after the Action Filters, and the AuditApiGlobalFilter is an Action Filter.您应该使用提供的中间件来获取响应标头,因为大多数响应标头都添加到在操作过滤器之后执行的结果过滤器上,并且AuditApiGlobalFilter是一个操作过滤器。

在此处输入图像描述

The recommended approach is to configure both the action filter and the middleware so you get specific information for the action and also any information added afterwards such as the response headers. 推荐的方法是同时配置操作过滤器中间件,以便您获得操作的特定信息以及之后添加的任何信息,例如响应标头。 Also, including the middleware will allow to audit requests that does not reach a controller/action.此外,包括中间件将允许审核未到达控制器/操作的请求。

So just add the following to your startup:因此,只需将以下内容添加到您的启动中:

public void Configure(IApplicationBuilder app)
{
    app.UseAuditMiddleware(_ => _
        .FilterByRequest(d => d.HttpContext.Request.Method != HttpMethods.Get)
        .IncludeHeaders()
        .IncludeResponseBody()
        .IncludeResponseHeaders()
        .WithEventType("{verb}.{controller}.{action}"));

    // ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM