private static SessionStateStoreData DeserializeSession(byte[] items, byte[] statics, int timeout) { SessionStateItemCollection itemCol = null; HttpStaticObjectsCollection staticCol = null; using (MemoryStream stream1 = new MemoryStream(items)) { using (BinaryReader reader1 = new BinaryReader(stream1)) { bool hasItems = reader1.ReadBoolean(); if (hasItems) { itemCol = SessionStateItemCollection.Deserialize(reader1); } else { itemCol = new SessionStateItemCollection(); } } } if (HttpContext.Current != null && HttpContext.Current.Application != null && HttpContext.Current.Application.StaticObjects != null && HttpContext.Current.Application.StaticObjects.Count > 0) { throw new ProviderException("This provider does not support static session objects because of security-related hosting constraints."); } if (statics != null && statics.Count() > 0) { throw new ProviderException("This provider does not support static session objects because of security-related hosting constraints."); } return(new SessionStateStoreData(itemCol, staticCol, timeout)); }
private static HttpSessionState CreateSessionState(string key, object state) { string id = key.Substring(CACHEKEYPREFIXLENGTH); ISessionStateItemCollection sessionItems = (ISessionStateItemCollection)ExpressionEvaluator.GetValue(state, "_sessionItems"); HttpStaticObjectsCollection staticObjects = (HttpStaticObjectsCollection)ExpressionEvaluator.GetValue(state, "_staticObjects"); int timeout = (int)ExpressionEvaluator.GetValue(state, "_timeout"); TypeRegistry.RegisterType("SessionStateModule", typeof(SessionStateModule)); HttpCookieMode cookieMode = (HttpCookieMode)ExpressionEvaluator.GetValue(null, "SessionStateModule.s_configCookieless"); SessionStateMode stateMode = (SessionStateMode)ExpressionEvaluator.GetValue(null, "SessionStateModule.s_configMode"); HttpSessionStateContainer container = new HttpSessionStateContainer( id , sessionItems , staticObjects , timeout , false , cookieMode , stateMode , true ); return((HttpSessionState)Activator.CreateInstance( typeof(HttpSessionState) , BindingFlags.Instance | BindingFlags.NonPublic , null , new object[] { container } , CultureInfo.InvariantCulture )); }
public static SessionStateStoreData Deserialize(byte[] buffer) { MemoryStream stream = new MemoryStream(buffer); SessionStateItemCollection itemCollection = null; HttpStaticObjectsCollection staticItemCollection = null; int timeout = 0; try { BinaryReader reader = new BinaryReader(stream); byte sessionFlag = reader.ReadByte(); if ((byte)(sessionFlag & SESSION_ITEMS) == SESSION_ITEMS) { itemCollection = SessionStateItemCollection.Deserialize(reader); } if ((byte)(sessionFlag & SESSION_STATIC_ITEMS) == SESSION_STATIC_ITEMS) { staticItemCollection = HttpStaticObjectsCollection.Deserialize(reader); } timeout = reader.ReadInt32(); } finally { if (stream != null) { stream.Close(); } } return(new SessionStateStoreData(itemCollection, staticItemCollection, timeout)); }
private static SessionStateStoreData DeserializeSession(byte[] items, IEnumerable <byte> statics, int timeout) { SessionStateItemCollection itemCol; const HttpStaticObjectsCollection StaticCol = null; using (var memoryStream = new MemoryStream(items)) { using (var binaryReader = new BinaryReader(memoryStream)) { bool hasItems = binaryReader.ReadBoolean(); itemCol = hasItems ? SessionStateItemCollection.Deserialize(binaryReader) : new SessionStateItemCollection(); } } if (HttpContext.Current != null && HttpContext.Current.Application != null && HttpContext.Current.Application.StaticObjects != null && HttpContext.Current.Application.StaticObjects.Count > 0) { throw new ProviderException("This provider does not support static session objects because of security-related hosting constraints."); } if (statics != null && statics.Count() > 0) { throw new ProviderException("This provider does not support static session objects because of security-related hosting constraints."); } return(new SessionStateStoreData(itemCol, StaticCol, timeout)); }
public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem) { LogUtils.WriteInfo("------------------ SetAndReleaseItemExclusive 1 ------------------"); ISessionStateItemCollection sessionItems = null; HttpStaticObjectsCollection staticObjects = null; if (item.Items.Count > 0) { sessionItems = item.Items; } if (!item.StaticObjects.NeverAccessed) { staticObjects = item.StaticObjects; } LogUtils.WriteInfo(context); LogUtils.WriteInfo(id); LogUtils.WriteInfo(item); LogUtils.WriteInfo(lockId); LogUtils.WriteInfo(newItem); LogUtils.WriteInfo(staticObjects); LogUtils.WriteInfo(sessionItems); MqdSessionState state2 = new MqdSessionState(sessionItems, staticObjects, item.Timeout); LogUtils.WriteInfo(state2); RedisUtils.SetString(id, state2.ToJson(), item.Timeout); LogUtils.WriteInfo("------------------ SetAndReleaseItemExclusive 2 ------------------\r\n"); }
public override void SetAndReleaseItemExclusive (HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem) { if (item == null) return; EnsureGoodId (id, true); byte[] collection_data = null; byte[] sobjs_data = null; MemoryStream stream = null; BinaryWriter writer = null; Stream output = null; #if NET_4_0 GZipStream gzip = null; #endif try { SessionStateItemCollection items = item.Items as SessionStateItemCollection; if (items != null && items.Count > 0) { stream = new MemoryStream (); #if NET_4_0 if (config.CompressionEnabled) output = gzip = new GZipStream (stream, CompressionMode.Compress, true); else #endif output = stream; writer = new BinaryWriter (output); items.Serialize (writer); #if NET_4_0 if (gzip != null) gzip.Close (); #endif writer.Close (); collection_data = stream.ToArray (); } HttpStaticObjectsCollection sobjs = item.StaticObjects; if (sobjs != null && sobjs.Count > 0) sobjs_data = sobjs.ToByteArray (); } catch (Exception ex) { throw new HttpException ("Failed to store session data.", ex); } finally { #if NET_4_0 if (writer != null) writer.Dispose (); if (gzip != null) gzip.Dispose (); #else if (writer != null) ((IDisposable)writer).Dispose (); #endif if (stream != null) stream.Dispose (); } stateServer.SetAndReleaseItemExclusive (id, collection_data, sobjs_data, lockId, item.Timeout, newItem); }
internal void InitStateStoreItem(bool addToContext) { this.ChangeImpersonation(this._rqContext, false); try { if (this._rqItem == null) { this._rqItem = this._store.CreateNewStoreData(this._rqContext, s_timeout); } this._rqSessionItems = this._rqItem.Items; if (this._rqSessionItems == null) { throw new HttpException(System.Web.SR.GetString("Null_value_for_SessionStateItemCollection")); } this._rqStaticObjects = this._rqItem.StaticObjects; this._rqSessionItems.Dirty = false; this._rqSessionState = new HttpSessionStateContainer(this, this._rqId, this._rqSessionItems, this._rqStaticObjects, this._rqItem.Timeout, this._rqIsNewSession, s_configCookieless, s_configMode, this._rqReadonly); if (addToContext) { SessionStateUtility.AddHttpSessionStateToContext(this._rqContext, this._rqSessionState); } } finally { this.RestoreImpersonation(); } }
private void InitStateStoreItem(bool addToContext) { Debug.Assert(_rqId != null, "_rqId != null"); if (_rqItem == null) { _rqItem = _store.CreateNewStoreData(_rqContext, s_timeout); } _rqSessionItems = _rqItem.Items; if (_rqSessionItems == null) { throw new HttpException(string.Format(SR.Null_value_for_SessionStateItemCollection)); } // No check for null because we allow our custom provider to return a null StaticObjects. _rqStaticObjects = _rqItem.StaticObjects; _rqSessionItems.Dirty = false; _rqSessionState = new HttpSessionStateContainer( _rqId, _rqSessionItems, _rqStaticObjects, _rqItem.Timeout, _rqIsNewSession, ConfigCookieless, s_configMode, _rqReadonly); if (addToContext) { SessionStateUtility.AddHttpSessionStateToContext(_rqContext.ApplicationInstance.Context, _rqSessionState); } }
/// <summary> /// Deserialise the session state data. /// </summary> /// <param name="items">The bytes to deserialise.</param> /// <param name="statics">The http static object collection.</param> /// <param name="timeout">The timeout for deserialisation.</param> /// <returns>The session state object.</returns> private SessionStateStoreData DeserializeSession(byte[] items, byte[] statics, int timeout) { MemoryStream stream1 = null, stream2 = null; BinaryReader reader1 = null, reader2 = null; try { stream1 = new MemoryStream(items); stream2 = new MemoryStream(statics); reader1 = new BinaryReader(stream1); reader2 = new BinaryReader(stream2); return(new SessionStateStoreData(SessionStateItemCollection.Deserialize(reader1), HttpStaticObjectsCollection.Deserialize(reader2), timeout)); } finally { if (reader2 != null) { reader2.Close(); } if (reader1 != null) { reader1.Close(); } if (stream2 != null) { stream2.Close(); } if (stream1 != null) { stream1.Close(); } } }
public HttpStaticObjectsCollectionWrapper(HttpStaticObjectsCollection httpStaticObjectsCollection) { if (httpStaticObjectsCollection == null) { throw new ArgumentNullException("httpStaticObjectsCollection"); } _collection = httpStaticObjectsCollection; }
public override void EndRequest(HttpContext context) { if (staticObjects != null) { staticObjects.GetObjects().Clear(); staticObjects = null; } }
public SessionStateStoreData(ISessionStateItemCollection sessionItems, HttpStaticObjectsCollection staticObjects, int timeout) { this.sessionItems = sessionItems; this.staticObjects = staticObjects; this.timeout = timeout; }
public SessionStateStoreData(ISessionStateItemCollection items, HttpStaticObjectsCollection objects, int timeout) { sessionItems = items; staticObjects = objects; this.timeout = timeout; }
public SessionStateValue( SessionStateItemCollection sessionItems, HttpStaticObjectsCollection staticObjects, int timeout) { SessionItems = sessionItems; StaticObjects = staticObjects; Timeout = timeout; }
/* In certain situations the 'item' parameter passed to SetAndReleaseItemExclusive * may be null. The issue was reported in bug #333898, but the reporter cannot * provide a test case that triggers the issue. Added work around the problem * in the way that should have the least impact on the rest of the code. If 'item' * is null, then the new session item is created without the items and staticItems * collections - they will be initialized to defaults when retrieving the session * item. This is not a correct fix, but since there is no test case this is the best * what can be done right now. */ public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem) { EnsureGoodId(id, true); string CacheId = CachePrefix + id; Cache cache = HttpRuntime.InternalCache; InProcSessionItem inProcItem = cache [CacheId] as InProcSessionItem; ISessionStateItemCollection itemItems = null; int itemTimeout = 20; HttpStaticObjectsCollection itemStaticItems = null; if (item != null) { itemItems = item.Items; itemTimeout = item.Timeout; itemStaticItems = item.StaticObjects; } if (newItem || inProcItem == null) { inProcItem = new InProcSessionItem(); inProcItem.timeout = itemTimeout; inProcItem.expiresAt = DateTime.UtcNow.AddMinutes(itemTimeout); if (lockId.GetType() == typeof(Int32)) { inProcItem.lockId = (Int32)lockId; } } else { if (lockId == null || lockId.GetType() != typeof(Int32) || inProcItem.lockId != (Int32)lockId) { return; } inProcItem.resettingTimeout = true; cache.Remove(CacheId); } try { inProcItem.rwlock.AcquireWriterLock(lockAcquireTimeout); inProcItem.locked = false; inProcItem.items = itemItems; inProcItem.staticItems = itemStaticItems; InsertSessionItem(inProcItem, itemTimeout, CacheId); } catch { throw; } finally { if (inProcItem.rwlock.IsWriterLockHeld) { inProcItem.rwlock.ReleaseWriterLock(); } } }
/// <summary> /// Creates a new SessionStateStoreData object to be used for the current request. /// </summary> /// <param name="context"></param> /// <param name="timeout"></param> /// <returns></returns> public override SessionStateStoreData CreateNewStoreData(HttpContext context, int timeout) { HttpStaticObjectsCollection sessionStatics = null; if (context != null) { sessionStatics = SessionStateUtility.GetSessionStaticObjects(context); } return(new SessionStateStoreData(new SessionStateItemCollection(), sessionStatics, timeout)); }
internal void Copy(ISessionStateItemCollection sessionItems, HttpStaticObjectsCollection staticObjects, int timeout, bool locked, DateTime utcLockDate, int lockCookie, int flags) { this._sessionItems = sessionItems; this._staticObjects = staticObjects; this._timeout = timeout; this._locked = locked; this._utcLockDate = utcLockDate; this._lockCookie = lockCookie; this._flags = flags; }
public void SetUp() { var configure = new MongoConfigurationBuilder(); configure.ConnectionStringAppSettingKey("mongoserver"); config = configure.BuildConfiguration(); SessionStateItemCollection sessionItemsCollection = new SessionStateItemCollection(); HttpStaticObjectsCollection staticObjectsCollection = new HttpStaticObjectsCollection(); item = new SessionStateStoreData(sessionItemsCollection, staticObjectsCollection, 1); }
public void Dispose () { if (rwlock != null) { rwlock.Dispose (); rwlock = null; } staticItems = null; if (items != null) items.Clear (); items = null; }
public override void Skip(CompactBinaryReader reader) { int cookie = reader.ReadInt32(); object custom = reader.Context.GetObject(cookie); if (custom == null) { custom = HttpStaticObjectsCollection.Deserialize(reader.BaseReader); reader.Context.RememberObject(custom, false); } }
/// <summary> /// Create a new SessionStateStoreData /// </summary> /// <param name="context">Httpcontext</param> /// <param name="timeout">Session timeout</param> /// <returns></returns> public override SessionStateStoreData CreateNewStoreData(HttpContextBase context, int timeout) { HttpStaticObjectsCollection staticObjects = null; if (context != null) { staticObjects = GetSessionStaticObjects(context.ApplicationInstance.Context); } return(new SessionStateStoreData(new SessionStateItemCollection(), staticObjects, timeout)); }
private static SessionStateValue DeserializeSessionState(BinaryReader reader) { var timeout = reader.ReadInt32(); var hasSessionItems = reader.ReadBoolean(); var hasStaticObjects = reader.ReadBoolean(); return(new SessionStateValue( hasSessionItems ? SessionStateItemCollection.Deserialize(reader) : null, hasStaticObjects ? HttpStaticObjectsCollection.Deserialize(reader) : null, timeout)); }
internal InProcSessionState( ISessionStateItemCollection sessionItems, HttpStaticObjectsCollection staticObjects, int timeout, bool locked, DateTime utcLockDate, int lockCookie, int flags) { Copy(sessionItems, staticObjects, timeout, locked, utcLockDate, lockCookie, flags); }
private static SessionStateStoreData CreateLegitStoreData(HttpContext context, int timeout) { ISessionStateItemCollection sessionItems = new SessionStateItemCollection(); HttpStaticObjectsCollection staticObjects = null; if (context != null) { staticObjects = SessionStateUtility.GetSessionStaticObjects(context); } return(new SessionStateStoreData(sessionItems, staticObjects, timeout)); }
private void AddStaticObjectAssemblyDependencies(HttpStaticObjectsCollection staticObjects) { if ((staticObjects != null) && (staticObjects.Objects != null)) { IDictionaryEnumerator enumerator = staticObjects.Objects.GetEnumerator(); while (enumerator.MoveNext()) { HttpStaticObjectsEntry entry = (HttpStaticObjectsEntry)enumerator.Value; base.AddTypeDependency(entry.ObjectType); } } }
public TaskWaitRedisHttpSessionStateContainer(string id, RedisSessionItemHash sessionItems, HttpStaticObjectsCollection staticObjects, int timeout, bool newSession, HttpCookieMode cookieMode, SessionStateMode mode, bool isReadonly) : base(id, sessionItems, staticObjects, timeout, newSession, cookieMode, mode, isReadonly) { SessionItems = sessionItems; }
internal InProcSessionState( SessionDictionary dict, HttpStaticObjectsCollection staticObjects, int timeout, bool isCookieless, int streamLength, bool locked, DateTime utcLockDate, int lockCookie) { Copy(dict, staticObjects, timeout, isCookieless, streamLength, locked, utcLockDate, lockCookie); }
internal HttpSessionStateContainer(SessionStateModule stateModule, string id, ISessionStateItemCollection sessionItems, HttpStaticObjectsCollection staticObjects, int timeout, bool newSession, HttpCookieMode cookieMode, SessionStateMode mode, bool isReadonly) { this._stateModule = stateModule; this._id = id; this._sessionItems = sessionItems; this._staticObjects = staticObjects; this._timeout = timeout; this._newSession = newSession; this._cookieMode = cookieMode; this._mode = mode; this._isReadonly = isReadonly; }
internal InProcSessionItem () { this.locked = false; this.cookieless = false; this.items = null; this.staticItems = null; this.lockedTime = DateTime.MinValue; this.expiresAt = DateTime.MinValue; this.rwlock = new ReaderWriterLockSlim (); this.lockId = Int32.MinValue; this.timeout = 0; this.resettingTimeout = false; }
internal InProcSessionItem() { this.locked = false; this.cookieless = false; this.items = null; this.staticItems = null; this.lockedTime = DateTime.MinValue; this.expiresAt = DateTime.MinValue; this.rwlock = new ReaderWriterLockSlim(); this.lockId = Int32.MinValue; this.timeout = 0; this.resettingTimeout = false; }
/// <summary> /// Uses a <see cref="BinaryFormatter"/> to read an object of /// type <see cref="ActualType"/> from the underlying stream. /// </summary> /// <param name="reader">stream reader</param> /// <returns>object read from the stream reader</returns> public override object Read(CompactBinaryReader reader) { int cookie = reader.ReadInt32(); object custom = reader.Context.GetObject(cookie); if (custom == null) { // custom = formatter.Deserialize(reader.BaseReader.BaseStream); custom = HttpStaticObjectsCollection.Deserialize(reader.BaseReader); reader.Context.RememberObject(custom, false); } return(custom); }
public void Serialization() { MemoryStream ms = new MemoryStream(); BinaryWriter writer = new BinaryWriter(ms); HttpStaticObjectsCollection hsoc = new HttpStaticObjectsCollection(); hsoc.Serialize(writer); ms.Position = 0; BinaryReader reader = new BinaryReader(ms); Assert.IsNotNull(HttpStaticObjectsCollection.Deserialize(reader)); }
internal HttpSessionState (string id, SessionDictionary dict, HttpStaticObjectsCollection staticObjects, int timeout, bool newSession, bool isCookieless, SessionStateMode mode, bool isReadonly) { _id = id; _dict = dict; _staticObjects = staticObjects.Clone (); _timeout = timeout; _newSession = newSession; _isCookieless = isCookieless; _mode = mode; _isReadonly = isReadonly; }
public HttpSessionStateContainer (string id, ISessionStateItemCollection sessionItems, HttpStaticObjectsCollection staticObjects, int timeout, bool newSession, HttpCookieMode cookieMode, SessionStateMode mode, bool isReadonly) { if (id == null) throw new ArgumentNullException ("id"); this.sessionItems = sessionItems; this.id = id; this.staticObjects = staticObjects; this.timeout = timeout; this.newSession = newSession; this.cookieMode = cookieMode; this.mode = mode; this.isReadOnly = isReadonly; this.isCookieless = cookieMode == HttpCookieMode.UseUri; }
public SessionStateStoreData(ISessionStateItemCollection sessionItems, HttpStaticObjectsCollection staticObjects, int timeout) { _sessionItems = sessionItems; _staticObjects = staticObjects; _timeout = timeout; }
void ResetPerRequestFields() { Debug.Assert(_rqIctx == null, "_rqIctx == null"); Debug.Assert(_rqChangeImpersonationRefCount == 0, "_rqChangeImpersonationRefCount == 0"); _rqSessionState = null; _rqId = null; _rqSessionItems = null; _rqStaticObjects = null; _rqIsNewSession = false; _rqSessionStateNotFound = true; _rqReadonly = false; _rqItem = null; _rqContext = null; _rqAr = null; _rqLockId = null; _rqInCallback = 0; _rqLastPollCompleted = DateTime.MinValue; _rqExecutionTimeout = TimeSpan.Zero; _rqAddedCookie = false; _rqIdNew = false; _rqActionFlags = 0; _rqIctx = null; _rqChangeImpersonationRefCount = 0; _rqTimerThreadImpersonationIctx = null; _rqSupportSessionIdReissue = false; }
/* * Process an Object tag, depending on its scope */ private void ProcessObjectTag(ObjectTagBuilder objectBuilder) { ObjectTagScope scope = objectBuilder.Scope; CheckObjectTagScope(ref scope); // Page and AppInstance are treated identically if (scope == ObjectTagScope.Page || scope == ObjectTagScope.AppInstance) { if (_pageObjectList == null) _pageObjectList = new ArrayList(); _pageObjectList.Add(objectBuilder); } else if (scope == ObjectTagScope.Session) { if (_sessionObjects == null) _sessionObjects = new HttpStaticObjectsCollection(); _sessionObjects.Add(objectBuilder.ID, objectBuilder.ObjectType, objectBuilder.LateBound); } else if (scope == ObjectTagScope.Application) { if (_applicationObjects == null) _applicationObjects = new HttpStaticObjectsCollection(); _applicationObjects.Add(objectBuilder.ID, objectBuilder.ObjectType, objectBuilder.LateBound); } else { Debug.Assert(false, "Unexpected scope!"); } }
internal void InitStateStoreItem(bool addToContext) { Debug.Assert(_rqId != null || s_allowInProcOptimization, "_rqId != null || s_allowInProcOptimization"); ChangeImpersonation(_rqContext, false); try { if (_rqItem == null) { Debug.Trace("InitStateStoreItem", "Creating new session state"); _rqItem = _store.CreateNewStoreData(_rqContext, s_timeout); } _rqSessionItems = _rqItem.Items; if (_rqSessionItems == null) { throw new HttpException(SR.GetString(SR.Null_value_for_SessionStateItemCollection)); } // No check for null because we allow our custom provider to return a null StaticObjects. _rqStaticObjects = _rqItem.StaticObjects; _rqSessionItems.Dirty = false; _rqSessionState = new HttpSessionStateContainer( this, _rqId, // could be null if we're using InProc optimization _rqSessionItems, _rqStaticObjects, _rqItem.Timeout, _rqIsNewSession, s_configCookieless, s_configMode, _rqReadonly); if (addToContext) { SessionStateUtility.AddHttpSessionStateToContext(_rqContext, _rqSessionState); } } finally { RestoreImpersonation(); } }
public override void InitializeRequest (HttpContext context) { staticObjects = HttpApplicationFactory.ApplicationState.SessionObjects.Clone (); }
public override void EndRequest (HttpContext context) { if (staticObjects != null) { staticObjects.GetObjects ().Clear (); staticObjects = null; } }
/* * Add assembly dependencies for a collection of static objects */ private void AddStaticObjectAssemblyDependencies(HttpStaticObjectsCollection staticObjects) { if (staticObjects == null || staticObjects.Objects == null) return; IDictionaryEnumerator en = staticObjects.Objects.GetEnumerator(); while (en.MoveNext()) { HttpStaticObjectsEntry entry = (HttpStaticObjectsEntry)en.Value; AddTypeDependency(entry.ObjectType); } }