ASP.NET core MVC动作过滤器执行顺序

ASP.NET core MVC动作过滤器执行顺序,第1张

概述using Microsoft.AspNetCore.Mvc.Filters;using System;using System.Threading.Tasks;namespace dotnet_core.Filter{ public class MyFilterAttribute: ActionFilterAttribute { publ
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);        }    }}

 

总结

以上是内存溢出为你收集整理的ASP.NET core MVC动作过滤器执行顺序全部内容,希望文章能够帮你解决ASP.NET core MVC动作过滤器执行顺序所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1226645.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存