1

我想在身份验证和会话超时之前显示弹出警告。警告弹出应该可以选择保持登录或退出。我几乎完成了功能,但有时单击保持登录按钮会将用户重定向到登录页面。我设置了相同的身份验证和会话超时值。我正在使用超时插件来显示警告。这就是我的代码的样子

timer = null;
    $(document).ready(function () {            
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_endRequest(EndRequestHandler);

        SetTimeoutDialog();
    });

    // show warning message to users before session timeout
    function SetTimeoutDialog() {

    //clear previous timers
        if (timer != null)
            clearInterval(timer);

        $.get('/GetRemainingTimeout.aspx', function (data) {
            var timeout = parseInt(data);
            timer = setInterval(function () {
                $.timeoutDialog({ timeout: 0, countdown: 180, keep_alive_url: '/KeepSessionAlive.aspx', logout_url: '/Logout.aspx', logout_redirect_url: '/Login.aspx', restart_on_yes: false });
            }, (timeout - 180000));
        });
    }

    function EndRequestHandler(sender, args) {
        SetTimeoutDialog();
    }

此外,这就是 GetRemainingTimeout.aspx.cs 中的代码的样子

protected void Page_Load(object sender, EventArgs e)
        {
            DateTime dateNow = DateTime.Now;
            if (HttpContext.Current.User.Identity is FormsIdentity)
            {
                HttpCookie authCookie = this.Context.Request.Cookies[FormsAuthentication.FormsCookieName];
                FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
                double leftMilliSeconds = (authTicket.Expiration - dateNow).TotalMilliseconds;
                // Control in MasterPage, where I setting value and then taking for JavaSript to CountDown message
                Response.Write(leftMilliSeconds > 0 ? leftMilliSeconds.ToString() : "0");
            } 
        }
4

0 回答 0