views:

196

answers:

1

Hi

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

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"

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.

Here is my code in Master page:

$(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:

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

Appreciate your responses.

+1  A: 

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.

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.

Amry
True... I am also wondering what the difference between redirect_url and the logout_url parameters. Let me check on that.
Rita