ASP.NET 中的会话超时警告 [英] Session Timeout Warning in ASP.NET

查看:25
本文介绍了ASP.NET 中的会话超时警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 asp.net 站点,当会话超时(比如说 10 分钟)时,我需要有一个弹出窗口/层/警报发生.弹出窗口会说您的帐户会话将因不活动而过期,并有一个继续会话按钮或注销按钮.

I have an asp.net site that I need to have a popup/layer/alert happen when the session reaches its timeout (lets say 10 minutes). The popup will say that your account session will exprire due to inactivity and have a button for continue session or a button for logout.

我在网上看到了不同的方法来做到这一点,但处理这个问题的最佳/正确方法是什么?如果弹出窗口打开时间过长,我是否必须设置额外的超时时间?

I see different ways to do this online, but what's the best/proper way to handle this? Do I have to put an additional timeout if the popup is open too long?

推荐答案

<script type="text/javascript">
    var sessionTimeoutWarning = "<%= System.Configuration.ConfigurationManager.AppSettings["SessionWarning"].ToString()%>";
        var sessionTimeout = "<%= Session.Timeout %>";

    var sTimeout = parseInt(sessionTimeoutWarning) * 60 * 1000;
    setTimeout('SessionWarning()', sTimeout);

    function SessionWarning() {
        var message = "Your session will expire in another " +
            (parseInt(sessionTimeout) - parseInt(sessionTimeoutWarning)) +
            " mins! Please Save the data before the session expires";
        alert(message);
    }
</script>

这篇关于ASP.NET 中的会话超时警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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