After logout if browser back button press then it go back last screen
You need to add the cache META
Tag for all the last page you visited
So add this for all the pages, by making a CustomAttribute like [NoCache]
and decorate
public class NoCacheAttribute : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
filterContext.HttpContext.Response.Cache.SetNoStore();
base.OnResultExecuting(filterContext);
}
}
public class AccountController : Controller
{
[NoCache]
public ActionResult Logout()
{
return View();
}
}
Or try it with javascript on the page like
<SCRIPT type="text/javascript">
window.history.forward();
function noBack() { window.history.forward(); }
</SCRIPT>
<BODY onload="noBack();"
onpageshow="if (event.persisted) noBack();" onunload="">
I had this problem a while ago, disabling the cache for the entire application solved my problem, just add these line to the Global.asax.cs
file
protected void Application_BeginRequest()
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();
}
Hope this helps.
Easiest way for a MVC 5 Application is:
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
Above each of the Controller Methods you don't want to Cache. Or if you are using .Core the following works:
[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
Have a nice day!