【发布时间】:2020-12-21 06:03:59
【问题描述】:
我在我的 ASP.NET Core 应用程序中使用剃须刀页面。我需要使用Audit.NET library 启用日志记录,它适用于 ASP.NET MVC 控制器,但不适用于 Razor 页面。
这是一个示例,我如何使用 Audit 属性声明 PageModel 类:
[Audit(EventTypeName = "{area}/{Page} ({verb})",
IncludeResponseBody = true,
IncludeRequestBody = true,
IncludeHeaders = true,
IncludeModel = true)]
public class LoginIndexModel : PageModel
{
...
}
当AuditAttribute 动作过滤器被调用时,它会抛出NullReferenceException。
这是AuditAttribute中声明的方法:
(据我了解actionDescriptor 参数不能转换为ControllerActionDescriptor)
private bool IsActionIgnored(ActionDescriptor actionDescriptor)
{
if (actionDescriptor == null)
return false;
return ((IEnumerable<object>)(actionDescriptor as ControllerActionDescriptor).ControllerTypeInfo
.GetCustomAttributes(typeof(AuditIgnoreAttribute), true)).Any<object>() ||
((IEnumerable<object>)(actionDescriptor as ControllerActionDescriptor).MethodInfo
.GetCustomAttributes(typeof(AuditIgnoreAttribute), true)).Any<object>();
}
那么在这种情况下我该怎么办? 有没有人遇到过类似的问题?
【问题讨论】:
-
这需要一些工作才能使其与 Razor Pages 兼容,我创建了 the following issue 来跟踪进度
标签: asp.net-core razor-pages audit.net