JQuery idleTimeout plugin: how to display dialog after session based on time in ASP.NET MVC page

I am working on porting an ASP.NET application to the MVC Framework. I have set a session timeout for InActiveUser using the IdleTimeout JQuery plugin.

I have set idletime for 30 minutes as shown below on my main page. So, after the user session has timed out 30 minutes, the Auto Shutdown dialog is displayed for a few seconds and says " you are about to log out due to inactivity "

Now after that the user will be logged out and redirected to the main page. Here I want to show the dialog again and have to stay there saying " You are logged out " until the user clicks on it.

Here is my code on the homepage:

$(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: ''
            });
        <%} %>

      

}

Exit () Method in Account Controller:

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

      

Rate your answers.

+2


a source to share


2 answers


How about instead of redirecting to a url, you redirect to a javascript function that does whatever you want it to do first and then redirect the url from 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: Although I'm wondering what the difference is between the parameters redirect_url

and logout_url

.

+1


a source


Try Seesion with JQuery Warning from my blog:



  • The session is set to timeout (for example, 30 minutes).
  • When the session time expires, the user is logged out.
  • Display a countdown to let the user know how much time is left.
  • Let the user know when he is nearing the limit (for example, 5 minutes).
  • Inform the user that they were automatically disabled due to inactivity.
0


a source







All Articles