public ActionResult Login(Users users, string ReturnUrl) { if (ModelState.IsValid) { using (GcomptesContext db = new GcomptesContext()) { var us = db.Users.Where(u => u.Username.Equals(users.Username) && u.Password.Equals(users.Password)).FirstOrDefault(); if (us != null) { FormsAuthentication.SetAuthCookie(us.UsersID.ToString(), false); Session["username"] = us.Username.ToString(); if (!string.IsNullOrWhiteSpace(ReturnUrl) && Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } } ModelState.AddModelError("Users.Username", "Username et/ou Password incorrect(s)"); } } return(View(users)); }