(ASP.NET) How to determine how long a user has been on a site?
I need to display a warning to a user if they've been on my site for five minutes and haven't signed in.
How should I do it?
Can I add soemthing for the session to Application_Start? Is there a way to check the duration of the session? Perhaps put something on the title page / home page and if it is longer than five minutes, give a warning?
Any help would be appreciated.
Thank.
EDIT ---
What I ended up with was using the asp: Timer control found with AjaxControlToolKit.
source to share
The answer lies in Globals.asax, but Application_Start is wrong. This is used when the ASP.NET application actually starts.
I would add DateTime.Now to the session in the Session_Start method in Globals.asax. Then you can check this on every page load (for example, on the main page or on the main page load page) or use Ajax to poll the server.
source to share
Application_Start is fired when the IIS application is initially loaded. Session_Start will start for every new session that starts.
If you are storing the current time in the session in Session_Start, you can check either the page load or the ajax call to determine if five minutes have passed without them logging in.
source to share