我在登出时遇到禁用浏览器后退按钮的问题

时间:2014-01-04 10:09:24

标签: javascript html asp.net-mvc-4 back-button

我正在使用mvc4,我在登出时遇到了禁用后退按钮的问题,注销链接在_Topheader视图上,我在这里编写了javascript代码,

<a href="/Account/LogOff" onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">Logout
</a>
<script type="text/javascript">
   window.history.forward();
   function noBack() { 
     window.history.forward(); 
   }

在注销后禁用所有后退按钮,如果我登录并切换到不同的页面,它也会禁用后退按钮。我只需要在每次退出后都禁用它

请为此建议解决方案。

3 个答案:

答案 0 :(得分:0)

当您注销会话时会破坏。在会话未使用时禁用后退按钮。会话在用户登录时设置,当时启用后退按钮。我不知道这会对你有帮助吗?

答案 1 :(得分:0)

这是一篇关于会话"Web security" works pretty simple with ASP.NET MVC 4

的文章

重点是,使用属性[Authorize]可以保护Controller,因此如果用户注销了。服务器将拒绝这些页面的请求。

我希望这会有所帮助。

答案 2 :(得分:0)

在注销页面后使用以下代码。

 function DisableBackButton() {
        changeHashOnLoad()
    }
    DisableBackButton();
    window.onload = DisableBackButton;
    window.onpageshow = function (evt) { if (evt.persisted) DisableBackButton() }
    window.onunload = function () { void (o) }
    function changeHashOnLoad() {
        window.location.href += "#";
        setTimeout("changeHashAgain()", "50");
    }
    function changeHashAgain() {
        window.location.href += "1";
    }
    var storedHash = window.location.hash;
    window.setInterval(function () {
        if (window.location.hash != storedHash) {
            window.location.hash = storedHash;
        }
    },
    50);
相关问题