Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid user being signed out when working locally

I use the CookieAuthenticationOptions.ExpireTimeSpan to set the timespan for the user session. And it works fine - maybee too good. When the user works by filling out textboxes etc., there is no server activity, which causes that when the user press Save, he is being signed out - and looses all entered data.

Is there any way where I can update timestamp, to prevent time expires when the user works without postback?

I have some ideas:

  • JavaScript polling/pinging - which may be spoiling the point to sign out user when she/he leaves the client computer, after some time.
  • Make some javacript to catch keypress event and send some ping to server, but that may be hard to implement, since I use a lot of forms.
  • Redirect user to last used webform at re-post data - if it is possible.

I am using AngularJS 1.4.7 as JavaScript framework.

like image 902
JorgenV Avatar asked Mar 12 '26 19:03

JorgenV


1 Answers

Why not use a preprocessor directive to set an alternate expiration time if the solution is in debug mode?

var options = new CookieAuthenticationOptions {
#if DEBUG
    ExpireTimeSpan = System.Timespan.FromDays(1)
#else
    ExpireTimespan = System.Timespan.FromMinutes(20) //or your preferred timespan
#endif
}
like image 120
Simmetric Avatar answered Mar 14 '26 09:03

Simmetric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!