Search code examples
asp.net-core-2.1

Capture Session timeout on Server side in asp.net core 2.1


I need to do something on Session End Event. How can I access this event? anything similar to this event maybe timeout?


Solution

  • The only way to handle this in ASP.NET Core - on page load on client side (in JS code) to schedule the timer for session timeout and warn the user when it's close to expire. If user responds - ping server side (to refresh the session), or redirect the user to logout page. Your session timeout can be configured in Startup class. So you need to pass the same value to client view, setup a timer (let say it is 20 minutes) to show the modal after 19 minutes to the user with counting down timer for a minute and a button like "Stay Online". When the user clicks the button - do AJAX call to server side (some Ping action in your Home controller, or something like that).