0

I have an active website built using VS 2013, MVC 5 and EF 6. This is for use in hospitals. One problem we have is that users are sometimes called away while entering data and without saving the current entry. When they return the session has expired and they have lost any unsaved data. Leaving aside any discussion on what users should do,what I want to do is to detect, either on the server (preferred) or the client when a session is about to expire so that remedial action can be taken. (I known how to do this part).

Extending session timeout is not a solution as it will not detect those situations where the user has forgotten to logout or has just closed the browser.

There are plenty of examples of handling session timeouts; what I cannot find is anything on how to detect these potential timeouts before they occur.

Are there any examples of solutions to this problem?

Peter Smith
  • 5,528
  • 8
  • 51
  • 77
  • Why don't you just increase session duration? If short session is the problem then make it longer. – Medo May 28 '15 at 09:36
  • Sorry - I meant to add that increasing session timeout is not an option. – Peter Smith May 28 '15 at 09:39
  • 1
    http://stackoverflow.com/questions/3308918/what-is-the-best-approach-to-handle-session-timeouts-in-asp-net Add something like this to the pages that need longer session so that it doesn't expire. Another option would be on post to check if request came from one of the pages that need longer session. If it did and session expired save your post data and show it on relog. All i could think off – Medo May 28 '15 at 09:40
  • Thanks for the link - it doesn't quite hit the spot but might provide a starting point – Peter Smith May 28 '15 at 10:22

2 Answers2

1

The easy way to do this is to set timer on the client using javascript, set the timer to less than the session value and perform whatever action you need to when the timer ticks. You also need to reset the timers on any action that would also reset the session.

var timeout;
var timeouttime = value in miliseconds
functionStart(){call this on initial page load
timeout = setTimeout("Function()", timeouttime}
function{"Function()"{do what ever before the sessions expire}

You can do a similar thing on the server side, but I have always had issues with timers server side in asp.net, so the above is what I use quite regularly.

MaCron
  • 111
  • 6
0

I suggest you:

codeape
  • 97,830
  • 24
  • 159
  • 188