Keeping your site communicating back with a main site via an Http Handler. I would typically use a simple setup like this:
function heartbeat(timeout) {
setTimeout("triggerHeartbeat", timeout);
}
function triggerHeartbeat() {
$.get("/Heartbeat.ashx",
null,
function(data) {
heartbeat(600000);
},"json");
}
Now you have a heartbeat that will pulse every 10 minutes (the call in the Ajax query simply sets up the next triggerHeartbeat call to happen 10 minutes later. You could replace this with
setTimeout("triggerHearbeat", 600000);
if you wanted to get rid of the heartbeat method (don't forget you'll have to trigger the first call).
Anyway, that's all the code you need on the client side - other than putting the initial call to heartbeat in a $.ready method. You need to create an HttpHandler at the server side called Heartbeat.ashx. The code in it is as simple as this:
public HeartbeatHttpHandler : HttpHandler, IRequireSessionState
{
public bool IsReusable { get { return false; } }
public void ProcessRequest(HttpContext ctx)
{
if (ctx == null) throw new ArgumentNullException();
ctx.Session["Heartbeat"] = 1;
}
}
Don't forget to add this to your list of HttpHandlers, and you're good to go. You'll find many examples on the web that follow this pattern - the code isn't complex, and it's a very well understood solution to the problem.