Browser back button issue after logout.

Choice:-1: Set Response Cache settings in code-behind file for a page.


// Code disables caching by browser.

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();

Choice:-2: Set META tag for HTTP cache settings in your ASPX page header.


<META Http-Equiv="Cache-Control" Content="no-cache"/>
<META Http-Equiv="Pragma" Content="no-cache"/>
<META Http-Equiv="Expires" Content="0"/>

Choice:-3: Clear browser’s history through JavaScript using below script.


//clears browser history and redirects url

<SCRIPT LANGUAGE="javascript">
function ClearHistory()
{
var backlen = history.length;
history.go(-backlen);
window.location.href = loggedOutPageUrl
}
</SCRIPT

Choice:-4: Clear browser’s history through JavaScript injecting through code-behind file via Response.


protected void LogOut()
{
Session.Abandon();
string loggedOutPageUrl = "Logout.aspx";
Response.Write("<script language="'javascript'">");
Response.Write("function ClearHistory()");
Response.Write("{");
Response.Write(" var backlen=history.length;");
Response.Write(" history.go(-backlen);");
Response.Write(" window.location.href='" + loggedOutPageUrl + "'; ");
Response.Write("}");
Response.Write("</script>");
}

About the Author

avatar