I'm trying to do auto redirect when session timeout using WebForms. I searched but found the codes that sets the predefined limit. but they never reset when we press key or move pointer etc. I reset the session timeout using ajax by calling ajax on each mouse move and keypress but this effecting the other script in terms of performance making it slower etc. I have tried this clear and clean code for this job also applied some ajax but never succeeded. https://code.msdn.microsoft.com/Auto-redirect-to-login-e1782b2f
Here is my service that get the session expire time on each mouse move or keypress.
[WebMethod (EnableSession=true)]
public static string GETExpireTime()
{
DateTime date = DateTime.Now;
int sessionTimeout = HttpContext.Current.Session.Timeout;
DateTime dateExpress = date.AddMinutes(sessionTimeout);
return dateExpress.ToString("u", DateTimeFormatInfo.InvariantInfo).Replace("Z", "");
}
Here is how I'm resetting it in jquery.
$(document).ready(function () {
$(document).keyup(function () {
var data = {};
setCookie("express", generalAjax(data, 'GETExpireTime').d);
});
$('*').mouseenter(function () {
var data = {};
setCookie("express", generalAjax(data, 'GETExpireTime').d);
});
});
Please help me if there is another way to do this perfectly as all codes set predefined time and force logout after that interval But I need to reset at mouse move or keypress. Thanks