internal SessionStateStoreData CreateUninitializedItem2(HttpContext context, string id, int timeout) { SessionStateStoreData data = CreateNewStoreData(context, timeout); // 将Session数据写入文件 byte[] bytes = SessionUtils.SerializeStoreData(data, 7000); FileStore.SaveToFile(bytes, id); return(data); }
private SessionStateStoreData LoadSessionState(HttpContext context, string id, byte[] bytes) { using (MemoryStream memoryStream = new MemoryStream(bytes)) { try { SessionStateStoreData data = SessionUtils.DeserializeStoreData(context, memoryStream); return(SessionUtils.CreateLegitStoreData(context, data.Items, data.StaticObjects, data.Timeout)); } catch (EndOfStreamException ex1) { throw new EndOfStreamException("无效的会话数据,当前会话文件:" + FileStore.GetSessionFilePath(id), ex1); } catch (InvalidDataException ex2) { throw new InvalidDataException("无效的会话数据,当前会话文件:" + FileStore.GetSessionFilePath(id), ex2); } } }
/// <summary> /// 缓存过期导致的清理 /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="reason"></param> public void OnCacheItemRemoved(string key, object value, CacheItemRemovedReason reason) { if (reason == CacheItemRemovedReason.Expired) { // 删除Session数据文件 string id = key.Substring(CacheStore.KeyPrefix.Length); _fileStore.DeleteFile(id); if (this._expireCallback != null) { SessionStateStoreData state = (SessionStateStoreData)value; this._expireCallback(id, SessionUtils.CreateLegitStoreData(null, state.Items, state.StaticObjects, state.Timeout)); } } }
public override SessionStateStoreData CreateNewStoreData(HttpContext context, int timeout) { return(SessionUtils.CreateLegitStoreData(context, null, null, timeout)); }
public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem) { byte[] bytes = SessionUtils.SerializeStoreData(item, 7000); FileStore.SaveToFile(bytes, id); }