<script type="text/javascript">
var sess_pollInterval = 60000;
var sess_expirationMinutes = 20;
var sess_warningMinutes = 5;
var sess_intervalID;
var sess_lastActivity;
function initSession() {
sess_lastActivity = new Date();
sessSetInterval();
$(document).bind('keypress.session', function (ed, e) {
sessKeyPressed(ed, e);
});
}
function sessSetInterval() {
sess_intervalID = setInterval('sessInterval()', sess_pollInterval);
}
function sessClearInterval() {
clearInterval(sess_intervalID);
}
function sessKeyPressed(ed, e) {
sess_lastActivity = new Date();
}
function sessLogOut() {
window.location.href = 'Logout.aspx';
}
function sessInterval() {
var now = new Date();
//get milliseconds of differneces
var diff = now - sess_lastActivity;
//get minutes between differences
var diffMins = (diff / 1000 / 60);
if (diffMins >= sess_warningMinutes) {
//warn before expiring
//stop the timer
sessClearInterval();
//prompt for attention
var active = confirm('Your session will expire in ' +
(sess_expirationMinutes - sess_warningMinutes) +
' minutes (as of ' + now.toTimeString() + '),
press OK to remain logged in ' +
'or press Cancel to log off.
\nIf you are logged off any changes will be lost.');
if (active == true) {
now = new Date();
diff = now - sess_lastActivity;
diffMins = (diff / 1000 / 60);
if (diffMins > sess_expirationMinutes) {
sessLogOut();
}
else {
initSession();
sessSetInterval();
sess_lastActivity = new Date();
}
}
else {
sessLogOut();
}
}
}
initSession();
</script>
Saturday, May 27, 2017
Session Time out warning
Subscribe to:
Post Comments (Atom)
Encrypt/Decrypt the App.Config
Program.cs using System; using System.Diagnostics; using System.IO; namespace EncryptAppConfig { internal class Program { pr...
-
C# Style Guide Remember that at the end of the day these are only recommendations . Table of Contents Tooling General Layout Spa...
-
RazorGenerator Generator Types MvcHelper : Creates a static type that is best suited for writing Mvc specific helper methods. MvcV...
-
private XDocument RemoveNamespace(XDocument xdoc) { foreach (XElement e in xdoc.Root.Descendants()) { ...
No comments:
Post a Comment