I am using MVC2 and VS2010. We have created a web application but want to stop any browser re-visiting pages after the page has been left. We want to do this so that someone who is using a public computer who then leaves can feel safe. We dont want the scenario that a following user can just use the back button to view the first uses pages. I have tried [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")] This seems to work fine and I get a Web Page Expired. But if I press the browser back button again, the page will be displayed.
-
have you tried setting the last modified date? unsure if this is already done by mvc2 – Chris Apr 16 '12 at 13:46
1 Answers
I have quite a similar situation myself in wanting to prevent a browser back situation and have researched a few different solutions. The first and worst being a Java script function which takes the user back to the page they were on if they click the back button in the browser. It hides the problem rather than solving it but thought id mention it. The code as follows:
<script type="text/javascript" language="javascript">
function disableBackButton() {
window.history.forward()
}
disableBackButton();
window.onload = disableBackButton();
window.onpageshow = function (evt) { if (evt.persisted) disableBackButton() }
window.onunload = function () { void (0) };
</script>
This works for Firefox, Chrome and IE ok. You can just put this in your master page. Many people will tell you this is not the way to do things however as it intrudes on the well known browser behaviour etc etc
So my second suggestion is something I have seen here: Disable browser cache for entire ASP.NET website Which will not cache anything which is more inline with what you are wanting I think.
Another idea would be to pass a page or session token around and on actions check the token - if its invalid reroute to an error page. That would at least prevent a new user doing anything with the previous page.
Id be interested to know how you solved this, if you have solved it.

- 1
- 1

- 483
- 3
- 10