예제 #1
0
 public bool IsValidUser(UserDetailsModels u)
 {
     if (u.UserName == "Admin" && u.Password == "Admin")
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #2
0
        [HttpPost] //只为 Post 请求开启
        public ActionResult DoLogin(UserDetailsModels u)
        {
            StudentBusinessLayer sbl = new StudentBusinessLayer();

            if (sbl.IsValidUser(u))
            {
                //创建一个认证的 Cookie
                FormsAuthentication.SetAuthCookie(u.UserName, false);
                return(RedirectToAction("Index", "Student"));
            }
            else
            {
                ModelState.AddModelError("CredentialError", "Invalid Username or Password");
                return(View("Login"));
            }
        }