Ejemplo n.º 1
0
 public ActionResult Login(LogOnModel model, string returnUrl)
 {
     if (ModelState.IsValid)
     {
         if (Membership.ValidateUser(model.UserName, model.Password))
         {
             FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
             if (Url.IsLocalUrl(returnUrl))
             {
                 return Redirect(returnUrl);
             }
             else
             {
                 return RedirectToAction("Index", "Home");
             }
         }
         else
         {
             ModelState.AddModelError("", "Неправильный пароль или логин");
         }
     }
     return View(model);
 }
Ejemplo n.º 2
0
        public ActionResult LogAs(int userId)
        {
            LogOnModel model = new LogOnModel();
            User user = context.GetUserById(userId);
            model.UserName = user.Login;
            model.Password = user.Password;
            model.RememberMe = false;

            if (Membership.ValidateUser(model.UserName, model.Password))
            {
                FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                return RedirectToAction("Index", "Home");
            }

            return RedirectToAction("Index");
        }