I know that Httpcontext.Session in MVC C# has a default timeout period of 20minutes.
But what if is read every 10minutes? Will this extend the timeout period? Or will it still time out after 20mins even if it is read within the 20minutes?
and part 2#. assuming the httpcontext will not time out if it is read within the timeout period, Is it ok to store a dbcontext in a httpcontext.session?
code like this:
public GenericDal()
{
if (HttpContext.Current.Session["unitOfWorks"] == null)
{
unitOfWorks = new UnitOfWork();
HttpContext.Current.Session.Add("unitOfWorks", unitOfWorks);
}
else
{
unitOfWorks = (UnitOfWork)HttpContext.Current.Session["unitOfWorks"];
}
}
It uses a sliding expiration, so when you access it, the timeout gets extended.
https://msdn.microsoft.com/en-us/library/vstudio/ms178581(v=vs.100).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
And I wouldn't put the context in the session. The discussion about DBContext in the session is well documented -
One DbContext per web request... why?