【发布时间】:2019-09-02 04:02:09
【问题描述】:
我正在使用以下代码在 Web API 中执行审计功能:
[HttpGet]
public IHttpActionResult GetList()
{
//var dd = ((ClaimsIdentity) User.Identity).Claims.FirstOrDefault(x => x.Type == "UserId").Value;
AuditBAL auditBAL = new AuditBAL();
Audit audit = new Audit();
audit.TableName = TableName.Terms_TABLE;
audit.MenuId = Convert.ToInt64(PageEnum.Terms);
audit.ActionId = Convert.ToInt64(ActionEnum.List);
audit.UserId = Convert.ToInt64(((ClaimsIdentity) User.Identity).Claims.FirstOrDefault(x => x.Type == "UserId").Value);
auditBAL.Save(audit);
return Ok(new ResponceView<DataTable>()
{
ResponseObject = termBAL.GetList()
});
}
使用上述方法我可以审计所有事件,但我必须为所有控制器方法编写上述代码审计代码。
我希望它对所有方法通用所以我在 Web API 中使用动作过滤器,但我不知道如何在动作过滤器中获取传递审核对象或如何在动作过滤器中获取方法名称和控制器名称。一旦我将在操作过滤器中获得必要的信息,我就可以使用这些信息进行审核。
我想为异常过滤器做同样的事情(想在异常过滤器中获取方法名称和控制器名称)。
提前致谢。
【问题讨论】:
标签: asp.net-web-api asp.net-web-api2