MVC 3 登录、注销

1) 登录,成功后写入票据

          //判断用户密码是否正确
            if (new UserBLL().Logon(user.LoginName, user.LoginPassword) != null)
            {
                //正确。。       
                 FormsAuthentication.RedirectFromLoginPage(user.LoginName, false);
            }
            else
            {
                //错误
            }
            return View();

 2) 判定存在用户票据

filterContext.HttpContext.User.Identity.IsAuthenticated

3)注销

FormsAuthentication.SignOut();

PS:发现一个小BUG,登录,注销时,不能进行页面跳转(使用RedirectToAction()跳转,其他暂未测试。),否则失效。

原文地址:https://www.cnblogs.com/comsokey/p/2540257.html