实现自动注销+预警asp.net + jQuery的? [英] Implement auto log-out + warning in asp.net + jquery?

查看:186
本文介绍了实现自动注销+预警asp.net + jQuery的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多网站(银行网站为例) - 会议之前实施注销+ 1分钟警告即将到期(20​​分钟)

Many sites ( Bank webSite for example) - implement log-out + 1 minute warning before session is about to expire.( 20 minutes)

这个话​​题没有太大的讨论 - 见过的唯一的问题是香港专业教育学院使用asp.net成员 - 我不使用的)

每个用户都会有一个会话[lastActionTime]

本次会议将是更新现有的时间的时候:

this session will be update to current Time when :


  • 页面加载

  • Ajax请求已执行(因用户操作)

现在 - 当一个页面加载,我设置会话值。 (可以说19:00)

Now - when a page loads , I set the session value. (lets say 19:00)

此外,对于每一个Ajax请求(我的网站不创建回传 - 只有阿贾克斯jQuery的) - 我用 IRequiresSessionState 一个ASHX处理程序用于更新会话电流时间

Also , for every ajax request (my site doesnt create postbacks - only ajax jquery) - I use an ASHX handler with IRequiresSessionState which updates the session to current Time.

我用的是这样的:

jQuery(document).ajaxStart(function(){
    gotoHandlerAndUpdateSessionTime();
})

现在-the部分1分钟警告信息(您的会话即将到期的)前:

Now -the part for 1 minute before warning message ( " your session is about to expire ") :

每个Ajax回归事件或页面加载事件 - 我激活的的JavaScript 的setInterval [sessionTime-1] 分(20-1 = 19)。 (当然 - 取消所有$ P $光伏setIntervals ...)

Every ajax return event or page load event - I activate in javascript : setInterval with [sessionTime-1] minutes ( 20-1=19). ( and of course - cancelling all prev setIntervals... )

现在当事件(setInterval的)发生 - 这是截止时间前1分钟(19分钟)

now when the event (setInterval) occurs - it is 1 minute before expiration time : (19 min)

我显示警告DIV,用户可以选择<大骨节病>退出或<大骨节病>停留

I display a warning div , and the user can choose exit or stay .

问题:

1)如果在警告DIV用户剪掉preSS从无到有,从显示原理(之后的 1分钟的div 的)将我登录他出了什么?显示DIV,然后当我应该打开1分钟的setTimeout(如果没有pressed)登录他出去?

1) what if the user didnt press nothing on the warning div , How (after 1 minute from displaying the div) will I log him out ? Should I open a setTimeout of 1 minute when displaying the div and then (if nothing pressed) to log him out ?

2)它做它的正确方法吗?

2) is it the right way of doing it ?

3)不应该有在这整个故事奇怪的饼干? : - )

3) Shouldn't there be cookies in this whole weird story ? :-)

(请 - 没有会员 - 或表单认证)。
我还标注了这个问题,因为PHP,因为我知道这是有关PHP程序员,以及和我想从他们的知识听到。

推荐答案

Royi,要回答两个你的问题,我会说是的。我已经建立了这几次(一般用窗体身份验证),但基本上你有倒计时显示的第一个警告,然后是倒计时,为用户提供了X秒回答另一个计时器的计时器。我通常把X秒倒计时警告消息上,让他们看,他们还剩下多少时间。如果他们没有在规定的时间接听,来电获取对破坏会话,然后JavaScript可以重定向他们回到登录页面Logout.ashx(或其他)制成。我希望帮助。

Royi, to answer both of your questions, I would say YES. I've built these several times (usually with Forms Auth), but basically you have a timer that counts down to show the first warning, and then another timer that counts down and gives the user X seconds to answer. I usually put the X second count down on the warning message so they can see how much time they have left. If they don't answer in the allotted time, a call gets made to Logout.ashx (or whatever) that destroys the session and then the javascript can redirect them back to the login page. I hope that helps.

关于你的第三个问题,只要你追踪你不应该真正需要的Cookie会话。只要做到在C#中session_destroy()在PHP或Session.Abandon()当JavaScript的倒计时。

Regarding your third question, as long as you're tracking the session you shouldn't really need cookies. Just do a session_destroy() in PHP or Session.Abandon() in C# when the javascript timer counts down.

下面是一些code我用我的网站之一(也许不是最干净的,但你的想法):

Here's some code I'm using on one of my sites (might not be the cleanest, but you get the idea):

var timeoutPolled = 0;
var timeoutSeconds = 10;
var countDownCounter = 61;
var timeoutBetweenPolls = 5000;
var stopCountDown = false;

function InitializePollTimer(timeoutMinutes) {
    timeoutSeconds = timeoutMinutes * 60;

    StartPollTimer();
}

function StartPollTimer() {
    setTimeout(PollForTimeout, timeoutBetweenPolls);
}

function PollForTimeout() {
    timeoutPolled++;

    if ((timeoutPolled * timeoutBetweenPolls) > 1 * (timeoutSeconds * 1000)) {
        $("#timeoutDialog").dialog({
            autoOpen: false,
            bgiframe: true,
            resizable: false,
            height: 250,
            draggable: false,
            modal: true,
            zindex: 99999999,
            position: 'top',   
            open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); },       
            buttons: {
                "Continue using Website?": function() {
                    StopCountDown();

                    $.ajax({
                        type: "GET",
                        url: "RefreshSession.aspx",
                        cache: false
                    });

                    $(this).dialog("close");

                    timeoutPolled = 0;
                    StartPollTimer();
                },
                "Logout": function() {
                    Logout();
                }
            }
        });

        $("#timeoutDialog").dialog("open");

        countDownCounter = 61;

        CountDown();
    }
    else {
        StartPollTimer();
    }
}

function CountDown() {
    if (stopCountDown) {
        stopCountDown = false;
    }
    else {
        countDownCounter--;
        $("#countdownTimer").html(countDownCounter);

        if (countDownCounter > 0) {
            setTimeout(CountDown, 950);
        }
        else {
            Logout();
        }
    }
}

function StopCountDown() {
    stopCountDown = true;
}

function Logout() {
    window.location.href = 'Logout.aspx';
}

这篇关于实现自动注销+预警asp.net + jQuery的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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