简体   繁体   English

如何停止显示我已离开页面的浏览器后退按钮

[英]How to stop browser back button showing a page I have left

I am using MVC2 and VS2010. 我正在使用MVC2和VS2010。 We have created a web application but want to stop any browser re-visiting pages after the page has been left. 我们已经创建了一个Web应用程序,但是要在离开页面后停止任何浏览器重新访问该页面。 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. 我尝试过[OutputCache(NoStore = true,Duration = 0,VaryByParam =“ *”)],这似乎工作正常,并且我的网页已过期。 But if I press the browser back button again, the page will be displayed. 但是,如果我再次按浏览器的后退按钮,则会显示该页面。

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. 第一个也是最糟糕的是Java脚本功能,如果用户单击浏览器中的“后退”按钮,则会将用户带回到他们所在的页面。 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. 这适用于Firefox,Chrome和IE。 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. 因此,我的第二个建议是在这里看到的内容: 禁用整个ASP.NET网站的浏览器缓存,该缓存不会缓存任何与您想要的内容更加内联的内容。

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. 如果您已解决问题,我很想知道您是如何解决的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击浏览器的后退按钮,如何获得同一页面 - how can i get the same page with the click of back button of browser 如何停止已经登录的用户使用浏览器的后退按钮再次登录? - How do I stop already logged in user to login again using back button of the browser? 如何停止客户端按下浏览器后退按钮上的表单重新提交 - How to stop form resubmission on browser back button being pressed by the client 如何在单页上显示主详细信息页面和后退按钮 - How do I have master details page and a back button on single page 如何创建将部分用作Web浏览器的Page Back的表单按钮? - How can I create a form button that will partially function as web browser's Page Back? 当我单击浏览器的后退按钮时,我仍然返回上一页 - When i click on back button of the browser i still get back to back page 如何恢复浏览器上一页上的后退按钮单击? - how to restore the previous page on browser back button Click? Selenium在浏览器后退按钮操作后使用旧页面,并且未显示对DOM的更改 - Selenium using the old page after browser back button action and not showing alterations to DOM 单击按钮后停止页面发布 - Stop page post back on button click 单击后退按钮时停止重定向页面 - Stop redirect page on back button click
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM