在我的Startup.cs中,当时间跨度达到30分钟后,我将使用以下代码终止会话。
services.AddSession(options => {
options.IdleTimeout = TimeSpan.FromMinutes(30); //Session Timeout.
});
what I am trying to achieve in my Startup.cs is that I want to include some sort of bool TimeExpired = true;
when session expired and add the following code to update my database:
if(TimedExpired)
{
RecordsContext oContext = new RecordsContext();
List<Users> lUsers = oContext.Users.ToList();
for(int i = 0; i < lUsers.Count; i++)
{
if(lUsers[i].usernameid == HttpContext.Session.GetString("usernameid")
{
lUsers[i].IsUserLoggedIn = false;
oContext.SaveChanges();
break;
}
}
}