dynamic Javascript popup message during session time out

Hi All,
Advance thanks.
I am using VS2017 and C#. I set the session time out for 20 minutes in the configuration file.

1) I need the popup with continue button to show user warning message the system is going to sign out in 1 minute .
2)If continue button is pressed, session continues for next 2 minutes.

Please help me! Any links or code are useful at this point.

Kind regards,
Pooja
poojasureshkumarAsked:
Who is Participating?
 
RobOwner (Aidellio)Commented:
The page and subsequent javascript need to be told how long to go before the session times out.  When you load the page you need to set a javascript variable, much like:

var timeout=<%=[timeout in ms]%>

Javascript works in milliseconds so you'll need to convert your c# session timeout accordingly if it is not already in ms.

in Javascript you can then use the setTimeout() function to show a popup at different times

e.g.

setTimeout("alert('Your session will expire in 2min')", timeout-120000);

you could modify that further to use the confirm() function that will tell you if they click ok to continue their session

setTimeout(function(){
  var r = confirm("Click OK to continue your session");
  if (r==true) {
    alert('continuing session');
  }
  else {
    alert('session cancelled');
  }
}, 1000);

Open in new window

0
 
poojasureshkumarAuthor Commented:
Hi Rob,
Thanks for the response.
My client requirement is to show the alert  when  session is about to expire.
If user logs in and remain idle for 20 minutes,has to show alert saying "session expires soon"..


Kind regards,
Pooja
0
 
RobOwner (Aidellio)Commented:
Hi,

So that's essentially what the code I posted above does.  It will show an alert saying that their session expires soon.  You will need to tweak that to suit your client.

Please let me know what else is missing and where I can help.

Cheers,
Rob
0
 
Julian HansenCommented:
You are also going to need to be able to call back to the server to update the session time.

The JavaScript can give you a heads up when it is about to expire but you will need to touch the server using a script that resets the session to 2min.

On the client side all you need is a setTimeout that expires 2 min before the session is about to expire. When this happens you check the last UI interaction and reset the timer accordingly.

In other words. When the keyboard is touched or mouse moved / clicked you set a lastUITouch to the current time. When the setTimeout runs out if that value is updated you AJAX the server and update the session timeout. If it has not changed you pop a warning to the user and start a countdown clock.

This is an alternative to the setInterval that runs from the beginning.

Before going to code - how do you plan to reset session time on the server?
0
 
Julian HansenCommented:
Watchit with the above

Your initial timeout is 20 min and then you reset to 2min - what are the rules for this? You don't want to set session timeout to 2min 10min into your original 20 - what are the rules around this?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.