You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从Angular UI输入向AuditInfo添加注释?

如何将Angular前端传入的注释添加到ABP审计日志中

实现步骤

1. Angular前端携带注释信息

发起请求时,通过自定义请求头将注释传递给后端,示例代码:

import { HttpClient, HttpHeaders } from '@angular/common/http';

// 构造请求头,加入审计注释
const headers = new HttpHeaders().set('X-Audit-Comment', '用户提交了订单修改申请');

// 发起请求时携带该请求头
this.http.post('/api/orders/update', orderData, { headers }).subscribe();

2. 后端审计日志贡献者获取并添加注释

修改你现有的MyAuditLogContributor类,从请求上下文中提取前端传入的注释,再添加到审计日志:

using Volo.Abp.AuditLogging;
using Volo.Abp.Http;

public class MyAuditLogContributor : AuditLogContributor
{
    public override void PostContribute(AuditLogContributionContext context)
    {
        // 从HttpContext中获取自定义请求头的注释内容
        var httpContextAccessor = context.ServiceProvider.GetRequiredService<IHttpContextAccessor>();
        var comment = httpContextAccessor.HttpContext?.Request.Headers["X-Audit-Comment"].FirstOrDefault();

        // 注释非空时添加到审计日志
        if (!string.IsNullOrWhiteSpace(comment))
        {
            context.AuditInfo.Comments.Add(comment);
        }
    }
}

注意事项

  • 确保后端已注入IHttpContextAccessor服务(ABP框架默认已配置,若未配置可在模块类中添加services.AddHttpContextAccessor())。
  • 若注释包含敏感内容,建议提前做过滤或加密处理。

内容的提问来源于stack exchange,提问作者lukkr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 11:27:10