0

My scenario:

I have a website that need to logout a user when a countdown is zero.Normally the code related to the timer will be on the master page. I have tried using the asp timer and session and it works but the problem is that the timer keeps reloading the child pages also and am unable to use drop down list on the child page due to the page frequently refreshing.

Countdown value is stored in db and if user log out before countdown is zero i need to save the remaining timeleft in db.

I was thinking of another alternatives,may be JavaScript calling the server side session to get the Countdown time(varies for every user) and sending back the time to the server once certain condition are met.

Is there a better solution? Can anyone provide some code for JavaScript version also.

keshav
  • 35
  • 8

2 Answers2

0

You can store in a database the login date time and the logout date time, so you can calculate the time spent on the site.

CyberZeus
  • 211
  • 1
  • 5
  • i actually have a countdown that its value stored on db. i need that countdown to reach zero to logout the user – keshav Oct 11 '19 at 09:02
  • You can check the countdown every time a page is requested. Take a look at Application_BeginRequest method of Global.asax.cs. – CyberZeus Oct 11 '19 at 09:52
0

What you could do is as you mention a master page, use Ajax to send a post request to a WebMethod - also see here for official documentation; and then in the WebMethod you query your database to return the time a user should be logged out from (let's assume you have one) a user table. You can put your Ajax method in a loop on the master page to send a request to check your database table for the user's log out time every minute - once the current time exceeds the log out time you will compare in the WebMethod, clear their session.