using Microsoft.AspNetCore.Mvc.Filters; using System; using System.Threading.Tasks; namespace dotnet_core.Filter{ public class MyFilterAttribute: ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterCo
using Microsoft.AspNetCore.Mvc.Filters; using System; using System.Threading.Tasks; namespace dotnet_core.Filter { public class MyFilterAttribute: ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { Console.WriteLine("方法执行之前!"); } public override void OnActionExecuted(ActionExecutedContext context) { Console.WriteLine("方法执行之后!"); base.OnActionExecuted(context); } public override void OnResultExecuting(ResultExecutingContext context) { Console.WriteLine("返回结果之前!"); base.OnResultExecuting(context); } public override Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { Console.WriteLine("在OnActionExecuting之前执行"); return base.OnActionExecutionAsync(context, next); } public override Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { //return Task.FromResult(0); Console.WriteLine("OnResultExecuting之前执行"); return base.OnResultExecutionAsync(context, next); } public override void OnResultExecuted(ResultExecutedContext context) { Console.WriteLine("返回结果之后"); base.OnResultExecuted(context); } } }