/// <summary> /// 执行 /// </summary> /// <param name="context">操作执行上下文</param> /// <param name="next">委托</param> /// <returns></returns> public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (next == null) { throw new ArgumentNullException(nameof(next)); } ActionFilterAttribute actionFilterAttribute = this; actionFilterAttribute.OnActionExecuting(context); await OnActionExecutingAsync(context); if (context.Result != null) { return; } var executedContext = await next(); actionFilterAttribute.OnActionExecuted(executedContext); }
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { _traceWriter.TraceBeginEnd( actionExecutedContext.Request, TraceCategories.FiltersCategory, TraceLevel.Info, _innerFilter.GetType().Name, ActionExecutedMethodName, beginTrace: (tr) => { tr.Message = Error.Format( SRResources.TraceActionFilterMessage, FormattingUtilities.ActionDescriptorToString( actionExecutedContext.ActionContext.ActionDescriptor)); tr.Exception = actionExecutedContext.Exception; HttpResponseMessage response = actionExecutedContext.Response; if (response != null) { tr.Status = response.StatusCode; } }, execute: () => { _innerFilter.OnActionExecuted(actionExecutedContext); }, endTrace: (tr) => { tr.Exception = actionExecutedContext.Exception; HttpResponseMessage response = actionExecutedContext.Response; if (response != null) { tr.Status = response.StatusCode; } }, errorTrace: (tr) => { HttpResponseMessage response = actionExecutedContext.Response; if (response != null) { tr.Status = response.StatusCode; } }); }