public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { if (MembershipService.ValidateUser(model.UserName, model.Password)) { FormsService.SignIn(model.UserName, model.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 View(model); }
public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { // Utilizando o Modo LoOnModel com a camada do Entity usersEntities context = new usersEntities(); var usuario = context.usuarios.Where(c => c.userName == model.UserName && c.password == model.Password).FirstOrDefault(); if (usuario != null) { Session["Usuario"] = usuario.userName; return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError(string.Empty, "Usuario ou senha incorreto."); //return RedirectToAction("LogOn", "Account"); //throw new Exception("Usuario ou senha incorreto"); } } return View(model); }