MVC 过滤器验证基础

3431人阅读 2021/4/2 17:38 总访问:669592 评论:0 收藏:0 手机
分类: .net mvc

过滤器大部分操作都需要通过filterContext点出来

         public void OnActionExecuting(ActionExecutingContext filterContext)
        {
                //获取Session的值
            var username = filterContext.HttpContext.Session["UserName"];
            var pwd = filterContext.HttpContext.Session["pwd"];
            //页面跳转(方法一)
            Controller controller = filterContext.Controller as Controller;
            if (username == null || pwd == null)
            {
             controller.HttpContext.Response.Redirect("/join/index");
            }
            //页面跳转(方法二)
            filterContext.Result = new RedirectResult("/Home/Index");
            
            //获取控制器名字
            string contextname =  filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
            
            //return可以跳过验证
           
        }


评价
脚踏实地,一步一个脚印
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术