private CookieSessionState GetFromCookie() { HttpCookie cookie = HttpContext.Current.Request.Cookies[CookieName]; if (cookie == null) { return(null); } return(CookieSessionState.FromJson(cookie.Value)); }
private void SaveToCookie(CookieSessionState state, int?timeout) { string json = state.ToJson(); HttpCookie cookie = new HttpCookie(CookieName, json); cookie.HttpOnly = true; if (timeout.HasValue && timeout > 0) { cookie.Expires = DateTime.Now.AddMinutes(timeout.Value); } HttpContext.Current.Response.AppendCookie(cookie); }
private SessionStateStoreData DoGet(HttpContext context, string id, bool exclusive, out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actionFlags) { locked = false; lockId = null; lockAge = TimeSpan.Zero; actionFlags = SessionStateActions.None; CookieSessionState state = GetFromCookie(); if (state == null) { return(null); } return(CreateLegitStoreData(context, state._sessionItems, state._staticObjects, state._timeout)); }
public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem) { ISessionStateItemCollection sessionItems = null; HttpStaticObjectsCollection staticObjects = null; if (item.Items.Count > 0) { sessionItems = item.Items; } if (!item.StaticObjects.NeverAccessed) { staticObjects = item.StaticObjects; } CookieSessionState state2 = new CookieSessionState(sessionItems, staticObjects, item.Timeout); SaveToCookie(state2, state2._timeout); }
public override void CreateUninitializedItem(HttpContext context, string id, int timeout) { CookieSessionState state = new CookieSessionState(null, null, timeout); SaveToCookie(state, timeout); }