2

I want to automatically after being sometimes idle by the user but not being able to do.I has used follwing javascript but nothing is going on and I have also add session timeout in web config but its also not working.Please give me some ideas.

<script type="text/javascript">
        var timer1, timer2;
        document.onkeypress=resetTimer;
        document.onmousemove=resetTimer;
        function resetTimer()
        {
            document.getElementById('timeoutPopup').style.display='none';
            clearTimeout(timer1);
            clearTimeout(timer2);

            // waiting time in minutes
            var wait=10;

            // alert user one minute before
            timer1=setTimeout("alertUser()", (60000*wait)-1);

            // logout user
            timer2=setTimeout("logout()", 60000*wait);
        }

        function alertUser()
        {
            document.getElementById('timeoutPopup').style.display='block';
        }

        function logout()
        {
            window.location.href='Logout.aspx';
        }



}



        </script>
user3247426
  • 127
  • 3
  • 16

3 Answers3

4

First argument for setTimeout is a function handle. JS Timing

<script type="text/javascript">
        var timer1, timer2;
        document.onkeypress=resetTimer;
        document.onmousemove=resetTimer;
        function resetTimer()
        {
           document.getElementById('timeoutPopup').style.display='none';
           clearTimeout(timer1);
           clearTimeout(timer2);
                // waiting time in minutes
            var wait=10;

           // alert user one minute before
            timer1=setTimeout(alertUser, (60000*wait)-1);

            // logout user
            timer2=setTimeout(logout, 60000*wait);
        }

        function alertUser()
        {
            document.getElementById('timeoutPopup').style.display='block';
        }

        function logout()
        {
            window.location.href='Logout.aspx';
        }



} </script>
vchyzhevskyi
  • 753
  • 1
  • 11
  • 20
0

You can achieve this by adding the following code in web config:

 <system.web>
    <sessionState timeout="10"></sessionState>
 </system.web>

Here timeout=10 implies after 10 Minutes, the session will be expired and therefore, automatic logout will be accomplished

user2978233
  • 55
  • 1
  • 1
  • 6
  • This would just make the session timeout, but an actual logout wont happen(unless you use the session to make an auth request)IF you are using forms authentication then please set the forms authentication time out to 10 and set the sliding expiration =false http://stackoverflow.com/questions/17812994/forms-authentication-timeout-vs-sessionstate-timeout – Rajat banerjee Mar 18 '14 at 07:24
  • Can you please explain me more with code.I really dont know what to do? – user3247426 Mar 18 '14 at 09:47
  • I have done like this but it is not working.. – user3247426 Mar 21 '14 at 05:33
-1

I think you can use html meta tag for this

<meta http-equiv="refresh" content="30">

This will cause your page to refresh after 30 seconds (change time as you need) and while refreshing you can check the session in your server side and can do the logic what you want.

Niju
  • 487
  • 1
  • 9
  • 18