Mvc 用户没有登录跳转到登录界面

登录时增加:

Session["UserName"] = model.UserName;

Controller:

 protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            //这里判断出没有登录然后进行跳转
            if (this.Session["UserName"] == null)
            {
                Response.Redirect("/Account/Login");
            }
        }
原文地址:https://www.cnblogs.com/gobuild/p/4919283.html