I am working with ASP.NET MVC 4 (NET Framework 4.0)
For a reason I do not understand, my user remains logged-in even after the browser or/and application restart. To take this further, even after a total computer restart, which means the authentification cookie/ticket is persisting.
I do not want to use cookieless
attribute in my Web.config
as I do not want to have the cookie stored in the URL for security and SEO issues.
I don't understand why is this happening, I have set the authentification cookie not to persist in the FormsAuthentication.SetAuthCookie()
method.
This is my login action, isValid(username, password)
is a custom method that checks if the username and password match in the model.
db
is my database context.
[AllowAnonymous]
[HttpPost]
public ActionResult LogIn(Employe user)
{
if (ModelState.IsValid)
{
if (IsValid(user.username, user.password))
{
FormsAuthentication.SetAuthCookie(user.username, false);
Employe currentEmp = db.Employes.SingleOrDefault(emp => emp.username == user.username);
Session["currentUser"] = currentEmp;
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", "Login Data Incorrect!");
}
}
return View();
}
This is my Web.config
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" protection="All" timeout="2880" />
</authentication>