1
In my MVC 5 project, a session with the user data is created in the login and after the re-execution of the application the Session no longer exists, however, the authentication Coockie still exists.
What can I do to keep you both active or destroy you both?
[HttpPost]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (!this.ModelState.IsValid)
return View(model);
if (Membership.ValidateUser(model.Usuario, model.Senha))
{
Session.Add("Usuario", new UsuarioModel { Nome = "Eu", Login = "Filipe"});
FormsAuthentication.SetAuthCookie(model.Usuario, false);
if (this.Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return this.Redirect(returnUrl);
}
return this.RedirectToAction("Index", "Home");
}
this.ModelState.AddModelError(string.Empty, "O usuário ou a senha são inválidos");
return View(model);
}