public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (!ShouldSaveAudit(context, out var auditLog, out var auditLogAction)) { await next(); return; } using (PlusCrossCuttingConcerns.Applying(context.Controller, PlusCrossCuttingConcerns.Auditing)) { var stopwatch = Stopwatch.StartNew(); try { var result = await next(); if (result.Exception != null && !result.ExceptionHandled) { auditLog.Exceptions.Add(result.Exception); } } catch (Exception ex) { auditLog.Exceptions.Add(ex); throw; } finally { stopwatch.Stop(); auditLogAction.ExecutionDuration = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds); auditLog.Actions.Add(auditLogAction); } } }
public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) { if (context.HandlerMethod == null || !context.ActionDescriptor.IsPageAction()) { await next(); return; } var methodInfo = context.HandlerMethod.MethodInfo; using (PlusCrossCuttingConcerns.Applying(context.HandlerInstance, PlusCrossCuttingConcerns.FeatureChecking)) { await _methodInvocationAuthorizationService.CheckAsync( new MethodInvocationFeatureCheckerContext(methodInfo) ); await next(); } }
public async Task OnActionExecutionAsync( ActionExecutingContext context, ActionExecutionDelegate next) { if (!context.ActionDescriptor.IsControllerAction()) { await next(); return; } var methodInfo = context.ActionDescriptor.GetMethodInfo(); using (PlusCrossCuttingConcerns.Applying(context.Controller, PlusCrossCuttingConcerns.FeatureChecking)) { await _methodInvocationAuthorizationService.CheckAsync( new MethodInvocationFeatureCheckerContext(methodInfo) ); await next(); } }