public ActionResult LogIn(SignInViewModel model, string returnUrl) { if (ModelState.IsValid) { if (_authenticationService.AuthenticateUser(model.SignInUserName, model.SignInPassword)) { //get accountId for this user int accountId = _membershipService.GetAccountId(model.SignInUserName); //create the authTicket that will hold user data string ticket = model.SignInUserName + "|" + accountId; _authenticationService.LogIn(ticket, createPersistentCookie: true); if (!String.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Incorrect username or password"); return(View()); } } else { return(View()); } }