protected void ReGenerateSessionId()
        {
            SessionIDManager manager = new SessionIDManager();
            string           oldId = manager.GetSessionID(System.Web.HttpContext.Current);
            string           newId = manager.CreateSessionID(System.Web.HttpContext.Current);
            bool             isAdd = false, isRedir = false;

            manager.RemoveSessionID(System.Web.HttpContext.Current);
            manager.SaveSessionID(System.Web.HttpContext.Current, newId, out isRedir, out isAdd);

            //Store data from old session
            HttpApplication      ctx  = System.Web.HttpContext.Current.ApplicationInstance;
            HttpModuleCollection mods = ctx.Modules;
            SessionStateModule   ssm  = (SessionStateModule)mods.Get("Session");

            FieldInfo[] fields = ssm.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
            SessionStateStoreProviderBase store = null;
            FieldInfo rqIdField = null, rqLockIdField = null, rqStateNotFoundField = null;

            SessionStateStoreData rqItem = null;

            foreach (FieldInfo field in fields)
            {
                if (field.Name.Equals("_store"))
                {
                    store = (SessionStateStoreProviderBase)field.GetValue(ssm);
                }
                if (field.Name.Equals("_rqId"))
                {
                    rqIdField = field;
                }
                if (field.Name.Equals("_rqLockId"))
                {
                    rqLockIdField = field;
                }
                if (field.Name.Equals("_rqSessionStateNotFound"))
                {
                    rqStateNotFoundField = field;
                }

                if ((field.Name.Equals("_rqItem")))
                {
                    rqItem = (SessionStateStoreData)field.GetValue(ssm);
                }
            }
            object lockId = rqLockIdField.GetValue(ssm);

            if ((lockId != null) && (oldId != null))
            {
                store.RemoveItem(System.Web.HttpContext.Current, oldId, lockId, rqItem);
            }

            rqStateNotFoundField.SetValue(ssm, true);
            rqIdField.SetValue(ssm, newId);
        }
Exemplo n.º 2
0
        /// <summary>
        /// sigh - this fixes a f****d up issue, where previewing pages containing code writing to Session,
        /// will breake all subsequent page previews regardless of content. Should you obtain the wisdom as
        /// to what exactly is the trick here, I'd love to now. I will leave it as "well, this fix the issue
        /// and pass testing. Hurray for Harry Potter and magic!". Oh how I loathe doing that :(
        /// </summary>
        /// <param name="ctx">the Http context that will be shared between master and child process</param>
        private static void AllowChildRequestSessionAccess(HttpContext ctx)
        {
            SessionIDManager manager = new SessionIDManager();
            string           oldId = manager.GetSessionID(ctx);
            string           newId = manager.CreateSessionID(ctx);
            bool             isAdd = false, isRedir = false;

            manager.SaveSessionID(ctx, newId, out isRedir, out isAdd);
            HttpApplication      ctx2 = (HttpApplication)HttpContext.Current.ApplicationInstance;
            HttpModuleCollection mods = ctx2.Modules;
            SessionStateModule   ssm  = (SessionStateModule)mods.Get("Session");

            System.Reflection.FieldInfo[] fields = ssm.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
            SessionStateStoreProviderBase store  = null;

            System.Reflection.FieldInfo rqIdField = null, rqLockIdField = null, rqStateNotFoundField = null;
            foreach (System.Reflection.FieldInfo field in fields)
            {
                if (field.Name.Equals("_store"))
                {
                    store = (SessionStateStoreProviderBase)field.GetValue(ssm);
                }
                if (field.Name.Equals("_rqId"))
                {
                    rqIdField = field;
                }
                if (field.Name.Equals("_rqLockId"))
                {
                    rqLockIdField = field;
                }
                if (field.Name.Equals("_rqSessionStateNotFound"))
                {
                    rqStateNotFoundField = field;
                }
            }
            object lockId = rqLockIdField.GetValue(ssm);

            if ((lockId != null) && (oldId != null))
            {
                store.ReleaseItemExclusive(ctx, oldId, lockId);
            }
            rqStateNotFoundField.SetValue(ssm, true);
            rqIdField.SetValue(ssm, newId);
        }
Exemplo n.º 3
0
        private void SetReadOnly(SessionStateModule module)
        {
            FieldInfo readOnly = module.GetType().GetField("_rqReadonly", BindingFlags.Instance | BindingFlags.NonPublic);

            readOnly.SetValue(module, true);
        }
Exemplo n.º 4
0
        private SessionStateStoreProviderBase GetProvider(SessionStateModule module)
        {
            FieldInfo store = module.GetType().GetField("_store", BindingFlags.Instance | BindingFlags.NonPublic);

            return((SessionStateStoreProviderBase)store.GetValue(module));
        }
Exemplo n.º 5
0
        private bool GetStateNotFound(SessionStateModule module)
        {
            FieldInfo stateNotFound = module.GetType().GetField("_rqSessionStateNotFound", BindingFlags.Instance | BindingFlags.NonPublic);

            return((bool)stateNotFound.GetValue(module));
        }
Exemplo n.º 6
0
        private SessionStateStoreData GetStoreData(SessionStateModule module)
        {
            FieldInfo item = module.GetType().GetField("_rqItem", BindingFlags.Instance | BindingFlags.NonPublic);

            return((SessionStateStoreData)item.GetValue(module));
        }
Exemplo n.º 7
0
        private object GetLockId(SessionStateModule module)
        {
            FieldInfo lockId = module.GetType().GetField("_rqLockId", BindingFlags.Instance | BindingFlags.NonPublic);

            return(lockId.GetValue(module));
        }