当前位置 : 主页 > 网络编程 > ASP >

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

来源:互联网 收集:自由互联 发布时间:2021-06-24
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);
        }
    }
}

 

网友评论