I am using razor pages in my ASP.NET Core application. I need to enable logging with Audit.NET library, it works fine with ASP.NET MVC controllers, but it doesn't work with Razor pages.
Here is an example how I declare a PageModel
class with Audit
attribute:
[Audit(EventTypeName = "{area}/{Page} ({verb})",
IncludeResponseBody = true,
IncludeRequestBody = true,
IncludeHeaders = true,
IncludeModel = true)]
public class LoginIndexModel : PageModel
{
...
}
It throws NullReferenceException
when AuditAttribute
action filter is invoked.
Here is the method declared in AuditAttribute
:
(As I understand actionDescriptor
parameter cannot be casted to 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>();
}
So what can I do in this case? Has anyone encountered a similar problem?