把判断用户是否登陆,没有登陆用过滤器直接返回登陆界面,,比较简单的方法001

1-1  首先定义一个类并且继承筛选器的基类

1-2 并且重写 在调用MVC框架至前调用的方法

       public class LoginJudgeAttribute:ActionFilterAttribute==>筛选器的基类
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            SessionUserInfo userInfo = HttpContext.Current.Session["UserInfo"] as SessionUserInfo;
            if (userInfo == null)
            {
                filterContext.Result = new RedirectResult("/User/Index");
            }
        }
    }

2-1 应用:直接在控制器的方法上定义标签==>类

    [LoginJudge]
        public ActionResult ShowCollection()
        {
            return View();
        }

posted @ 2016-04-18 09:52  蜡笔小新0998  阅读(503)  评论(0)    收藏  举报