I was trying to execute a SqlCommand after the TimeSpan ends. When the IdleTimeout has been called, the user would go into the homepage and need to login again. But in addition. I want to call a command for my Last Login:
//Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddControllersWithViews();
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(10);
});
services.AddMvc();
services.AddHsts(options =>
{
options.Preload = true;
options.IncludeSubDomains = true;
options.MaxAge = TimeSpan.FromDays(30);
});
}
I would like to add a SqlConnection and SqlCommand inside of this part of the code:
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(10);
});
I tried many things inside of it, after debugging. When the user logged in it will start the AddSession and I thought it will only execute when the TimeSpan ends. Where can I put the end of the command after Timespan ends?
Here's my scenario:
- When User logs in,
AddSessionstarts - When the user idled for 10 mins, it will execute the
SqlCommandwith last login - After executing the last login will update into new DateTime