MIlla
MIlla

Reputation: 45

Disable/deny going back to previous page on asp.net 2.0

On my current project I want to deny going back once my customers hit submit button and redirected to the final page. How can I deny from going back to previous page or some mechanism to expire the page if the back button is clicked. I tried this code and it didn't work

page.response.cache.setcacheability(httpcacheability.nocache)

Upvotes: 2

Views: 5189

Answers (3)

Abdul Khaliq
Abdul Khaliq

Reputation: 2285

I also had the same problem, use this Java script function, its 100% working fine, would not let you go back.

<script type = "text/javascript" >
  function preventBack(){window.history.forward();}
    setTimeout("preventBack()", 0);
    window.onunload=function(){null};
</script>

Upvotes: 0

Russ
Russ

Reputation: 11

<script type="text/javascript">
    history.forward();
</script>
</head>

<body>
<form runat="server" id="form1">
<%
    Response.Buffer = True
    Response.Expires = 0
    Response.ExpiresAbsolute = DateTime.Now.AddDays(-1)
    Response.CacheControl = "no-cache"
%>

I put this in my master page and it works great!! :-)

Upvotes: 1

ysrb
ysrb

Reputation: 6740

Place the following between the <head> </head> of ALL your pages:

<script type="text/javascript">
        history.forward();
</script>

And check this article out:

https://web.archive.org/web/20210927201700/http://www.4guysfromrolla.com/webtech/111500-1.shtml

Upvotes: 0

Related Questions