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,
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


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

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

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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,
RobOwner (Aidellio)Commented:

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.

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?
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?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.