Prevent browser back button to redirect to the previous page in asp.net mvc2

Posted by Santosh.Impossible under Others on 4/13/2013 | Points: 10 | Views : 15368 | Status : [Member] | Replies : 2
Hi WebGurus,

I have used the following article to create a POC on showing an Session expire warning message in a asp.net mvc2 application.
http://www.fairwaytech.com/2012/01/handling-session-timeout-gracefully/

I have made one change in the code as mentioned below:

location.href = expireSessionUrl; in the endSession method to the following code:

window.location.replace(expireSessionUrl);
and once user clicks on the Log Out button present in the Session warning message dialog box he is navigated to the LogOut view. But here if he clicks the browser back button he is navigated to the previous page.

I have the following modified Expire method as mentioned bleow:

[Authorize]
public virtual ActionResult Expire()
{
Session.Clear();
FormsService.SignOut();
HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Response.Cache.SetValidUntilExpires(false);
HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Response.Cache.SetNoStore();
return Redirect("/");
}
Can you please guide me in resolving the issue.

Thanks In Advance
Santosh Kumar Patro

santosh kumar patro


Responses

Posted by: Jitendrasoft09 on: 4/30/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi,
You have to override this function OnResultExecuting to prevent browser once user signed out or you can disabled the back button using javascript, please look into below link that would be helpful for you.
http://stackoverflow.com/questions/14437987/how-disable-browser-back-button-only-after-logout-in-mvc3-net

Jitendra Kumar
If my post helps you, plz mark as an answer.

Santosh.Impossible, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Valley on: 5/7/2013 [Member] Starter | Points: 25

Up
0
Down

<script type="text/javascript" language="javascript">
{
window.history.forward(1);
document.attachEvent("onkeydown", my_onkeydown_handler);
function my_onkeydown_handler()
{
switch (event.keyCode)
{
case 116: // F5;
event.returnValue = false;
event.keyCode = 0;
window.status = "We have disabled F5";
break;
}
}
</script>

Santosh.Impossible, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response