I am working on my own login/logout module in ASP.NET MVC 4 and I am clearing the session in my logout Action result and also not storing the cache using the following code.
[HttpGet]
public ActionResult Login()
{
return View();
}
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
[HttpPost]
public ActionResult Login(Models.User user)
{
if (ModelState.IsValid)
{
if (user.IsValid(user.UserName, user.Password))
{
FormsAuthentication.SetAuthCookie(user.UserName, user.RememberMe);
return RedirectToAction("Index", "Admin");
}
else
{
ModelState.AddModelError("", "Login data is incorrect!");
}
}
return View(user);
}
public ActionResult Logout()
{
FormsAuthentication.SignOut();
Session.Clear();
Session.Abandon();
Session.RemoveAll();
return RedirectToAction("Index", "Home");
}
Home Index Controller
[Authorize]
public ActionResult Index()
{
return View();
}
Layout cshtml
@if (Request.IsAuthenticated)
{
<strong>@Html.Encode(User.Identity.Name)</strong>
@Html.ActionLink("Sign Out", "Logout", "User")
@Html.ActionLink("Grid", "Index", "Admin")
}
else
{
@Html.ActionLink("Sign In", "Login", "User")
}
And I am using forms authentication and everything works fine but after I log out from the page, I am still able to access the secured page by clicking on back button.
May I know where I am making a mistake