views:

60

answers:

3

I need to display an alert to a user, if they have been on my site for five minutes and have not logged in.

How do I do that?

Would I add soemthing to session on Application_Start? Is there a way to just check the length of someone's session? Perhaps put something in the header/master page and if it exceeds five minutes throw up the alert?

Any help would be appreciated.

Thank you.

EDIT ---

What I ended up doing was using the asp:Timer control found with the AjaxControlToolKit.

+1  A: 

The answer does lie in Globals.asax, but Application_Start is not it. That is used for 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 either check it on each page load (for instance, in a base page or Master page's onload event), or use Ajax to poll the server.

JoshJordan
+5  A: 

Application_Start fires when the IIS Application initially gets loaded. Session_Start would fire for each new Session that gets started.

If you store the current time in the Session in Session_Start then you can check on either a page load or with an ajax call to determine if five minutes have passed without them logging in.

Bela
Agreed with Bela, although Application_Start doesn't really factor in to the solution. I would also add that if you're not using session state on the site you might use a hidden field or querystring value to passes between page calls that is either an encoded date/time or a link to a record that contains the date/time.
Jason Snelders
A: 

If you truly want a 5 minute check, you need to register a 5 minute ajax callback from Session_Start. The tricky part is having a page loaded and ready that can receive it when it fires.

Polling the server with AJAX is probably the more common approach.

rick schott