public IEnumerable<ICoroutineResult> InitializeSession(IHttpContext context) { if (_cacheEngine == null) yield break; if (context.Session != null) yield break; var newSession = new SimpleHttpSessionState(); var cookie = context.Request.Cookies[SessionConstants.SessionId]; if (cookie == null) { var nodecsSid = Guid.NewGuid().ToString(); cookie = new System.Web.HttpCookie(SessionConstants.SessionId, nodecsSid); context.Response.SetCookie(cookie); } newSession.SetSessionID(cookie.Value); var realSession = newSession; yield return _cacheEngine.AddAndGet(new CacheDefinition { Value = newSession, }, (a) => realSession = (SimpleHttpSessionState)a, "basicSessionManager"); context.SetSession(realSession); }