过滤器-ActionFilterAttribute

原文链接:https://www.cnblogs.com/ysmc/p/16512659.html
1
public class HttpContextFilter : ActionFilterAttribute 2 { 3 /// <summary> 4 /// Action执行之前执行OnActionExecuting(优先) 5 /// </summary> 6 /// <param name="context"></param> 7 /// <param name="next"></param> 8 /// <returns></returns> 9 public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) 10 { 11 12 await base.OnActionExecutionAsync(context, next); 13 } 14 15 /// <summary> 16 /// Action执行之前执行OnActionExecuting 17 /// </summary> 18 /// <param name="context"></param> 19 public override void OnActionExecuting(ActionExecutingContext context) 20 { 21 22 base.OnActionExecuting(context); 23 } 24 25 /// <summary> 26 /// Action执行之后执行OnActionExecuted 27 /// </summary> 28 /// <param name="context"></param> 29 public override void OnActionExecuted(ActionExecutedContext context) 30 { 31 32 base.OnActionExecuted(context); 33 } 34 35 /// <summary> 36 /// Action返回之后执行OnResultExecuted 37 /// </summary> 38 /// <param name="context"></param> 39 public override void OnResultExecuted(ResultExecutedContext context) 40 { 41 42 base.OnResultExecuted(context); 43 } 44 45 /// <summary> 46 /// Action返回之前执行OnResultExecuting 47 /// </summary> 48 /// <param name="context"></param> 49 public override void OnResultExecuting(ResultExecutingContext context) 50 { 51 52 base.OnResultExecuting(context); 53 } 54 55 /// <summary> 56 /// Action返回之前执行OnResultExecuting(优先) 57 /// </summary> 58 /// <param name="context"></param> 59 /// <param name="next"></param> 60 /// <returns></returns> 61 public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) 62 { 63 64 await base.OnResultExecutionAsync(context, next); 65 } 66 }

执行顺序

1、OnActionExecutionAsync
2、OnActionExecuting
3、OnActionExecuted
4、OnResultExecutionAsync
5、OnResultExecuting
6、OnResultExecuted
posted @ 2022-07-23 18:16  一事冇诚  阅读(2218)  评论(0编辑  收藏  举报