更好的注销方法 [英] Better way to handle logout

查看:90
本文介绍了更好的注销方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义退出页面.当用户单击注销时,将到达此页面(并且注销状态保存在数据库中).没有登录机制.如果用户在新窗口中尝试,则可以查看该页面,并且注销状态将更改为已登录.

I have a custom logout page. When user clicks logout this page is reached (and logout status is saved in database). There is no login mechanism. If a user tries in a new window he is allowed to view the page and logout status is changed as logged In.

注销后,当用户单击后退"按钮(从注销页面)时,不应允许用户查看前一页.

Once logged out, when user is clicking back button (from logout page), it should not allow user to view previous page.

类似:用户访问页面时,将存储时间.当他空闲20分钟并尝试进行操作时,他将被重定向到会话超时.他应该无法在单击后退按钮时查看上一页.

Similarly: When user access a page, the time is stored. When he is idle for 20 min and attempt an operation he will be redirected to session timed out. He should not be able to view previous page on back button click.

当前,在每个页面中,我正在检查数据库状态,如果状态已注销,则将再次重定向到注销的页面.但这会导致页面首先加载,然后在javascript中进行验证,然后重定向.有更好的方法来解决这个问题吗?

Currently in each page I am checking the database status and redirecting to logged out page again if status is logged out. But it causes the page to load first and then do validation in javascript and then redirect. Is there a better way to handle this?

注意:我将根据清除浏览器历史记录中的评论,将其作为新问题发布./p>

Note: I am posting it as a new question based on the comment in Clear browser history

        $.ajax(
        {
            type: "POST",
            url: "LogOut.aspx/GetActiveIndicatorStatus",
            data: '{"empID": "' + empID + '"}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: navigateBasedOnStatus

        }
        );


//Helper Function
function navigateBasedOnStatus(result) {


    if (result.hasOwnProperty("d")) {
        result = result.d
    }

    //alert($.trim(result));

    if ($.trim(result) == "LoggedOUT") {

        window.location.href("LogOut.aspx");
    }
    else 
    {
        contentHolderDiv.css("display", "block");
    }


}

参考:

  1. 清除浏览器历史记录
  2. 在< a>
  3. 上动态添加href >
  1. Clear browser history
  2. Dynamically add href on <a>

推荐答案

场景1:不要Ajax:

Scenario 1: don't Ajax:

如果您在页面上,则用户可能不会再看到

If you are on the page the user may not see again,

window.location.replace("LogOut.aspx/GetActiveIndicatorStatus?empID="+empID)

将您返回的页面替换为返回的页面.

will replace the page you are on with whatever you return.

方案2:替换结果:

if ($.trim(result) == "LoggedOUT") {

    window.location.replace("LogOut.aspx");
}
else 
{
    contentHolderDiv.css("display", "block");
}

这篇关于更好的注销方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆