• MVC 过滤器 ActionFilterAttribute


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using 过滤器.Controllers;
    
    namespace 过滤器.Filtes
    {
        public class MyActionFiterAttribute : ActionFilterAttribute
        {
    
            /// <summary>
            /// Action过滤器 执行方法之前
            /// </summary>
            /// <param name="filterContext"></param>
            public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                //RouteData保存了当前请求的路由信息
                // filterContext.RouteData.Values["action"];
                // filterContext.RouteData.DataTokens["area"]; 获取区域名称
                if (filterContext.ActionDescriptor.IsDefined(typeof(MyActionFiterAttribute), false))//检查当前请求的action是否有贴MyActionFiterAttribute标签
                {
                    //不执行Action方法,也不执行OnActionExecuted方法,会执行Result过滤器
                    filterContext.Result = new ContentResult();//给当前请求设置返回结果,不会再继续执行当前的action
                }
                filterContext.HttpContext.Response.Write("哈哈哈哈哈~!!!OnActionExecuting");
                base.OnActionExecuting(filterContext);
            }
            //执行方法之后
            public override void OnActionExecuted(ActionExecutedContext filterContext)
            {
                filterContext.HttpContext.Response.Write("哈哈哈哈哈~!!!OnActionExecuted");
                base.OnActionExecuted(filterContext);
            }
            //Result过滤器
            public override void OnResultExecuted(ResultExecutedContext filterContext)
            {
                filterContext.HttpContext.Response.Write("哈哈哈哈哈~!!!OnResultExecuted");
                base.OnResultExecuted(filterContext);
            }
            public override void OnResultExecuting(ResultExecutingContext filterContext)
            {
                filterContext.HttpContext.Response.Write("哈哈哈哈哈~!!!OnResultExecuting");
                base.OnResultExecuting(filterContext);
            }
        }
    }
  • 相关阅读:
    prometheus监控zookeeper
    prometheus监控mongo
    python游戏练手--乒乓球
    python游戏练手--贪吃蛇
    python爬虫练手--糗事百科图片获取
    Prometheus监控安装及使用(一)
    善用k8s explain
    k8s deployment
    k8s pod
    k8s deployment 金丝雀发布 更新的 暂停 恢复 回滚
  • 原文地址:https://www.cnblogs.com/sumg/p/3744054.html
Copyright © 2020-2023  润新知