Quote:
I want to disable back button only on login page when user logouts
No, you cannot disable back button of browser in any conditions. You need to rethink your application logic so that it doesn't matter if the user presses the back button. Don't try and mess with the browser. It's either going to only work sporadically, and then, only for those with javascript enabled, and is subject to the whims of those who write the browsers.
The correct method is invalidate the cache, along with server side validation that the session is no longer valid if they try to resend data. To do this, please check
Solution 1[
^] answer given by Tadit.
[Edit 1]
Added code block.
You can add this javascript to login page.
<script type="text/javascript" language="javascript">
function fnBackButton() {
window.history.forward()
}
fnBackButton();
window.onload = fnBackButton;
window.onpageshow = function (evt) { if (evt.persisted) fnBackButton() }
window.onunload = function () { void (0) }
</script>
Sometimes, javascript will not be enabled in client browser's. So I would suggest you to clear the cache in login page using c#. Use
Page_Init
even.
protected void Page_Init(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
}
--Amit