Hi to all,
Good day!
I would like to ask on how to implement fake session timeout if 30 minutes passed without intervention from the user like mouse click or keyboard press. My existing application is always refreshing just to check the status flag from database table. Because of this, the regular session timeout is not working because of the constant refreshing of the page. Now, I would like to ignore the page refreshing or page reloading in every two seconds and execute the session timeout if no intervention coming from the mouse or keyboard. is it possible? If yes, what would be the best or sample code that I gonna do to execute the session timeout even the page is always reloading. Once the session timeout is executed, the page will be re-directed to log-in page.
Thank you very much.
Below is my sample code in webconfig
What I have tried:
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="ActiveDirectoryDomainList" value="Domain_1;Domain_2" />
<add key="IActiveDirectoryAdapter" value="ExternalSystems.ActiveDirectoryMockAdapter, ExternalSystems" />
<add key="MemberFilter" value="Filter1,Filter2" />
<add key="SessionTimeOut" value="30" />
<add key="SqlCommandTimeOut" value="120" />
</appSettings>
Below is my SecurityController.cs
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogIn(LogInModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
model.IPAddress = Request.UserHostAddress;
model.SessionId = HttpContext.Session.SessionID;
model = SecurityBL.LogInUser(model);
if (model.ErrorList.Any())
{
ViewBag.Message = model.ErrorList.First().ErrorMessage;
return View(model);
}
FormsAuthentication.SetAuthCookie(model.UserName, false);
SessionManager.LastLogin = DateTime.Now.ToString();
SessionManager.EmployeeGroup = model.EmployeeGroup;
SessionManager.UserID = model.UserID;
Session.Timeout = Convert.ToInt32(model.SessionTimeout);
switch (model.EmployeeGroup)
{
case Constants.AccountingGroup:
return RedirectToAction("UserDashBoard", "AccountDashBoard");
case Constants.AdminGroup:
return RedirectToAction("AdminDashBoard", "AccountDashBoard");
default:
break;
}
return RedirectToAction("LogIn", "Security", new { info = "Identity not valid!" });
}