public ActionResult Login(LoginViewModel model,string returnUrl) { if (ModelState.IsValid) { var user = _repository.Users.FirstOrDefault(item => item.Username.ToLower() == model.Username.ToLower() && item.Password == model.Password); if (user == null || user.Password != model.Password) { ModelState.AddModelError("","The Username or password id correct"); return View(model); } FormsAuthentication.SetAuthCookie(model.Username, false); Session["User"] = user; if (!string.IsNullOrEmpty(returnUrl) && returnUrl !="/Product/ViewDetails") { return Redirect(returnUrl); } return RedirectToAction("List", "Product"); } return View(model); }
public ViewResult Login(string returnUrl) { var model = new LoginViewModel {Username = string.Empty, Password = string.Empty, returnUrl = returnUrl}; Session["User"] = null; return View(model); }