In my project in MVC 5, a session with user data is created at login and after re-execution of the Session application no longer exists, however, the Coockie authentication still exists.
What can I do to keep both active or destroy 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);
}