Skip to content

Instantly share code, notes, and snippets.

@Phuseos
Created March 22, 2017 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Phuseos/dad976550d878582c360fd88266ce9a8 to your computer and use it in GitHub Desktop.
Save Phuseos/dad976550d878582c360fd88266ce9a8 to your computer and use it in GitHub Desktop.
Handler + JavaScript that keep the session from timing out (C#)
<%@ WebHandler Language="C#" Class="KeepSessionAlive" %>
using System;
using System.Web;
using System.Web.SessionState;
//Handler that checks the session, when called from the Master page (see below) it will keep the session from idle time-out.
public class KeepSessionAlive : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Session["KeepSessionAlive"] = DateTime.Now;
}
public bool IsReusable
{
get
{
return false;
}
}
}
/*
JavaScript to put in the Site.Master
<script lang="javascript" type="text/javascript" src="https://code.jquery.com/jquery-latest.js"></script>
<script lang="javascript" type="text/javascript">
$(function () {
setInterval(KeepSessionAlive, 60000);
});
function KeepSessionAlive() {
$.post("/KeepSessionAlive.ashx", null, function () {
});
}
</script>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment