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>

3 Answers 3

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>
Sign up to request clarification or add additional context in comments.

Comments

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

3 Comments

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 stackoverflow.com/questions/17812994/…
Can you please explain me more with code.I really dont know what to do?
<authentication mode="Forms"> <forms loginUrl="~/default.aspx" timeout="1" slidingExpiration="true" /> </authentication> I have done like this but it is not working.. <sessionState timeout="5" />
-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.

3 Comments

where should I use that above tag?
but how to now whether the pahe has been idle or not.
this does not work ideally. it forces the page to refresh even if the user is doing something, which is inconvenient and poses a risk on losing unsaved data input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.