예제 #1
0
        public ActionResult Login(LoginModel login, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(login.UserName, login.Password))
                {
                    FormsAuthentication.SetAuthCookie(login.UserName, login.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return RedirectToAction("Index", "Home", login);

            //if (ModelState.IsValid && WebSecurity.Login(login.UserName, login.Password, persistCookie: true))
            //{
            //    return RedirectToLocal(returnUrl);
            //}
            //else
            //{
            //    return RedirectToAction("Index", "Home");
            //}
        }
예제 #2
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }
예제 #3
0
 public ActionResult Login(LoginModel model, string returnUrl)
 {
     if (ModelState.IsValid && WebSecurity.Login(model.Nickname, model.Password, persistCookie: model.RememberMe))
     {
         if (Url.IsLocalUrl(returnUrl))
         {
             return Redirect(returnUrl);
         }
         else
         {
             return RedirectToAction("Index", "Home");
         }
     }
     ModelState.AddModelError("", "The user name or password provided is incorrect.");
     return View(model);
 }