public ActionResult Login(vmLogin model, string returnUrl) { try { if (ModelState.IsValid) { UserType userType; var User = _Trainer.Login(model.Email, model.Password, out userType); if (User != null) { CreateSession(userType, User); FormsAuthentication.SetAuthCookie( User.Email, false); FormsAuthenticationTicket ticket1 = new FormsAuthenticationTicket( 1, User.Email, DateTime.Now, DateTime.Now.AddMinutes(20), false, User.Email); HttpCookie cookie1 = new HttpCookie( FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket1)); Response.Cookies.Add(cookie1); FormsAuthentication.RedirectFromLoginPage(User.Email, true); return(RedirectToAction("Index", "Home")); } } ViewData["Error"] = "Invalid Email or Password."; } catch (Exception ex) { ViewData["Error"] = ex.Message; } return(View(model)); }