I've an MVC 5 - based web project and i using HttpSessionStateWrapper class to work with session state.
Basicaly i store some user-specific data in session state.
Here is my code (without context):
public class Util
{
private HttpSessionStateWrapper _session;
public Util()
{
_session = new HttpSessionStateWrapper(HttpContext.Current.Session);
}
public T Get<T>(string key) where T : class
{
var sessionedObject = (T)_session[key];
if (sessionedObject != null)
{
Logger.Instance.LogDebug("Object returned from session. Session Timeout=" + _session.Timeout.ToString() + " Session Id=" + _session.SessionID);
return sessionedObject;
}
return null;
}
}
The instance of Util class is created one time and serves as a static property for another singleton type.
And i've some logging here. So, timeout of session state set to 1 minute via Web.config.
But it seems session never epxires for me even within 10 minutes.
Moreover, i noted than on each request SessionId is new, but when getting data from session, the id is equal to first-time generated session id.
Session End event also never fired for me, but Session Start does.
Here is some logs:
2013-11-11 04:27:38.2578 App Starting
2013-11-11 04:27:38.6641 Session onStart. Id=0x545pyzbt4e1vzh1h1rr5d5
2013-11-11 04:27:38.6641 Object returned from session. Session Timeout=1 Session Id=0x545pyzbt4e1vzh1h1rr5d5
2013-11-11 04:28:06.5263 Session onStart. Id=ujuxasiz5hvzbv15gbvuuxt3
2013-11-11 04:28:06.5263 Object returned from session. Session Timeout=1 Session Id=0x545pyzbt4e1vzh1h1rr5d5
2013-11-11 04:29:00.3432 Session onStart. Id=jgwmmh1ubokxn3kfadevfnph
2013-11-11 04:29:00.3432 Object returned from session. Session Timeout=1 Session Id=0x545pyzbt4e1vzh1h1rr5d5
2013-11-11 04:39:25.7919 Session onStart. Id=0mocujzp4tbwwvgnkx1mn0qi
2013-11-11 04:39:25.7919 Object returned from session. Session Timeout=1 Session Id=0x545pyzbt4e1vzh1h1rr5d5
EDIT:
Thanks for replies guys! I decide to refuse using session state at all due to have no time to deep debuging this stuff, and use HttpContext.Current.Items collection, it will serve my needs