Created
March 22, 2017 08:03
-
-
Save Phuseos/dad976550d878582c360fd88266ce9a8 to your computer and use it in GitHub Desktop.
Handler + JavaScript that keep the session from timing out (C#)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ 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