JQuery idleTimeout插件:如何在ASP.NET MVC页面上的会话超时后显示对话框

时间:2021-06-25 01:48:57

I am working on migrating the ASP.NET apllication to MVC Framework. I have implemented session timeout for InActiveUser using JQuery idleTimeout plugin.

我正在努力将ASP.NET apllication迁移到MVC Framework。我使用JQuery idleTimeout插件为InActiveUser实现了会话超时。

I have set idletime for 30 min as below in my Master Page. So that After the user session is timedout of 30 Min, an Auto Logout dialog shows for couple of seconds and says that "You are about to be signed out due to Inactivity"

我在主页面中将空闲时间设置为30分钟。因此,在用户会话超时30分钟后,“自动注销”对话框显示几秒钟,并显示“由于不活动而即将退出”

Now after this once the user is logged out and redirected to Home Page. Here i again want to show a Dialog and should stay there saying "You are Logged out" until the user clicks on it.

此后,一旦用户注销并重定向到主页。在这里,我再次想要显示一个Dialog,并且应该留在那里说“你被注销”,直到用户点击它。

Here is my code in Master page:

这是我在Master页面中的代码:

$(document).ready(function() {
        var SEC = 1000;
        var MIN = 60 * SEC;
        // http://philpalmieri.com/2009/09/jquery-session-auto-timeout-with-prompt/
        <% if(HttpContext.Current.User.Identity.IsAuthenticated) {%>
         $(document).idleTimeout({
            inactivity: 30 * MIN,
            noconfirm : 30 * SEC,
            redirect_url: '/Account/Logout',
            sessionAlive: 0, // 30000, //10 Minutes
            click_reset: true,
            alive_url: '',
            logout_url: ''
            });
        <%} %>

}

}

Logout() Method in Account Controller:

帐户控制器中的Logout()方法:

 public virtual ActionResult Logout() {
        FormsAuthentication.SignOut();
        return RedirectToAction(MVC.Home.Default());
    }

Appreciate your responses.

感谢您的回复。

2 个解决方案

#1


1  

How about instead of redirecting to a url, you redirect to a javascript function which does whatever you want it to do first, then redirect to the url from within the javascript.

如何而不是重定向到网址,你重定向到一个javascript函数,它执行你想要它做的任何事情,然后从JavaScript中重定向到网址。

function logout() {
    alert('You are about to be signed out due to Inactivity');
    window.location = '/Account/Logout';
}

$(document).ready(function() {
    var SEC = 1000;
    var MIN = 60 * SEC;
    // http://philpalmieri.com/2009/09/jquery-session-auto-timeout-with-prompt/
    <% if(HttpContext.Current.User.Identity.IsAuthenticated) {%>
     $(document).idleTimeout({
        inactivity: 30 * MIN,
        noconfirm : 30 * SEC,
        redirect_url: 'javascript:logout()',
        sessionAlive: 0, // 30000, //10 Minutes
        click_reset: true,
        alive_url: '',
        logout_url: ''
        });
    <%} %>

p/s: Though I do wonder what's the difference between the redirect_url and the logout_url parameters.

p / s:虽然我想知道redirect_url和logout_url参数之间的区别是什么。

#2


0  

Try This Seesion Alert Using Jquery from my blog:

从我的博客中使用Jquery尝试此Seesion警报:

  • Session set to time out (e.g. 30 minutes).
  • 会话设置为超时(例如30分钟)。
  • When session times out, the user is logged out.
  • 会话超时时,用户已注销。
  • Display a countdown so the user knows how long is left.
  • 显示倒计时,以便用户知道剩余时间。
  • Inform the user when they are approaching the limit (e.g. 5 minutes left).
  • 当用户接近极限时(例如,还剩5分钟)通知用户。
  • Let the user know that they’ve been automatically timed out due to inactivity.
  • 让用户知道他们由于不活动而自动超时。

#1


1  

How about instead of redirecting to a url, you redirect to a javascript function which does whatever you want it to do first, then redirect to the url from within the javascript.

如何而不是重定向到网址,你重定向到一个javascript函数,它执行你想要它做的任何事情,然后从JavaScript中重定向到网址。

function logout() {
    alert('You are about to be signed out due to Inactivity');
    window.location = '/Account/Logout';
}

$(document).ready(function() {
    var SEC = 1000;
    var MIN = 60 * SEC;
    // http://philpalmieri.com/2009/09/jquery-session-auto-timeout-with-prompt/
    <% if(HttpContext.Current.User.Identity.IsAuthenticated) {%>
     $(document).idleTimeout({
        inactivity: 30 * MIN,
        noconfirm : 30 * SEC,
        redirect_url: 'javascript:logout()',
        sessionAlive: 0, // 30000, //10 Minutes
        click_reset: true,
        alive_url: '',
        logout_url: ''
        });
    <%} %>

p/s: Though I do wonder what's the difference between the redirect_url and the logout_url parameters.

p / s:虽然我想知道redirect_url和logout_url参数之间的区别是什么。

#2


0  

Try This Seesion Alert Using Jquery from my blog:

从我的博客中使用Jquery尝试此Seesion警报:

  • Session set to time out (e.g. 30 minutes).
  • 会话设置为超时(例如30分钟)。
  • When session times out, the user is logged out.
  • 会话超时时,用户已注销。
  • Display a countdown so the user knows how long is left.
  • 显示倒计时,以便用户知道剩余时间。
  • Inform the user when they are approaching the limit (e.g. 5 minutes left).
  • 当用户接近极限时(例如,还剩5分钟)通知用户。
  • Let the user know that they’ve been automatically timed out due to inactivity.
  • 让用户知道他们由于不活动而自动超时。