In Asp.Net Core MVC 1.0 (MVC 6 RC1) the session timeout period is specified when session support is added in the ConfigureServices
method in Startup.cs like so:
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
options.CookieName = "Session";
});
My question is this: elsewhere in the application how can this IdleTimeout
value be accessed?
I would expect to find it as a property off of the HttpContext.Session object but it does not appear to be there. I've searched high and low and this doesn't seem to be documented anywhere. Thoughts?
This appears to be a private field inside of the DistributedSession
class. So at the moment, you can't get it. Session seems to be missing a lot of properties from the old HttpSessionState class, but I can't find anything pointing to what the reason may be (there might be a good one!).
You could get it with reflection, but it's pretty gnarly. The example below uses this answer.
public IActionResult Index()
{
var value = GetInstanceField(typeof(DistributedSession), HttpContext.Session, "_idleTimeout");
return View();
}
I would recommend storing the value in a configuration file or an internal class
somewhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With