Пример #1
0
 public void Deny_Unrestricted()
 {
     Assert.IsNotNull(coll.AllKeys, "AllKeys");
     coll.CopyTo(new object[0], 0);
     Assert.IsNull(coll.Get("mono"), "Get(string)");
     Assert.IsNull(coll["mono"], "this[string]");
     try {
         Assert.IsNull(coll[0], "this[int]");
     }
     catch (ArgumentOutOfRangeException) {
         // normal (can't avoid it)
     }
     try {
         Assert.IsNull(coll.GetKey(0), "GetKey(int)");
     }
     catch (ArgumentOutOfRangeException) {
         // normal (can't avoid it)
     }
     try {
         Assert.IsNull(coll.Get(0), "Get(int)");
     }
     catch (ArgumentOutOfRangeException) {
         // normal (can't avoid it)
     }
 }
Пример #2
0
        private string RegenrateSessionId()
        {
            var         manager = new SessionIDManager();
            HttpContext context = System.Web.HttpContext.Current;
            string      oldId = manager.GetSessionID(context);
            string      newId = manager.CreateSessionID(context);
            bool        isAdd = false, isRedir = false;

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

            FieldInfo[] fields = ssm.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
            SessionStateStoreProviderBase store = null;
            FieldInfo rqIdField = null, rqLockIdField = null, rqStateNotFoundField = 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 (rqLockIdField != null)
            {
                object lockId = rqLockIdField.GetValue(ssm);
                if ((lockId != null) && (oldId != null))
                {
                    if (store != null)
                    {
                        store.ReleaseItemExclusive(context, oldId, lockId);
                    }
                }
            }
            if (rqStateNotFoundField != null)
            {
                rqStateNotFoundField.SetValue(ssm, true);
            }
            if (rqIdField != null)
            {
                rqIdField.SetValue(ssm, newId);
            }
            return(newId);
        }
        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);
        }
Пример #4
0
 static IEnumerable <string> GetHttpModules(HttpModuleCollection modules)
 {
     if (modules != null)
     {
         return(modules.AllKeys.Select(key =>
                                       modules.Get(key).GetType().FullName
                                       .Replace("System.Web.Security", "").Replace("System.Web", ""))
                .ToArray());
     }
     return(Enumerable.Empty <string>());
 }
Пример #5
0
        public ActionResult Login(int?id)
        {
            //Session.Abandon();
            SessionIDManager manager = new SessionIDManager();

            manager.RemoveSessionID(System.Web.HttpContext.Current);
            var oldId        = manager.GetSessionID(System.Web.HttpContext.Current);
            var newId        = manager.CreateSessionID(System.Web.HttpContext.Current);
            var isRedirected = true;
            var isAdded      = true;

            manager.SaveSessionID(System.Web.HttpContext.Current, newId, out isRedirected, out isAdded);
            System.Web.HttpContext.Current.Session["sessionid"] = newId;
            HttpApplication      ctx  = (HttpApplication)System.Web.HttpContext.Current.ApplicationInstance;
            HttpModuleCollection mods = ctx.Modules;

            System.Web.SessionState.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(System.Web.HttpContext.Current, oldId, lockId);
            }
            rqStateNotFoundField.SetValue(ssm, true);
            rqIdField.SetValue(ssm, newId);

            ViewBag.CompanyID     = id;
            ViewBag.Message       = id.HasValue ? "" : "缺少公司标识";
            ViewBag.ThirdLoginUrl = string.Format("{0}?client_id={1}&redirect_uri={2}&state={3}&response_type=code", authorizeUrl, clinetId, redirectUri, state);
            return(View());
        }
Пример #6
0
        public static void RegenrateSessionId()
        {
            Authorization.AuthoCookie.RegenerateAuthoCookie();
            SessionIDManager manager = new SessionIDManager();
            string           oldId = manager.GetSessionID(HttpContext.Current);
            string           newId = manager.CreateSessionID(HttpContext.Current);
            bool             isAdd = false, isRedir = false;

            manager.SaveSessionID(HttpContext.Current, newId, out isRedir, out isAdd);
            HttpApplication      ctx  = (HttpApplication)HttpContext.Current.ApplicationInstance;
            HttpModuleCollection mods = ctx.Modules;

            System.Web.SessionState.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(HttpContext.Current, oldId, lockId);
            }
            rqStateNotFoundField.SetValue(ssm, true);
            rqIdField.SetValue(ssm, newId);
        }
 public static void Init(HttpApplication context)
 {
     if ((Interlocked.Exchange(ref _hasBeenInitialized, 1) != 1) && ((DynamicEntries.Count != 0) && (_reflectionUtil != null)))
     {
         IntPtr integratedModeContext = _reflectionUtil.GetIntegratedModeContext();
         if (integratedModeContext != IntPtr.Zero)
         {
             _reflectionUtil.SetModuleConfigInfo(null);
             HttpModuleCollection integratedModuleCollection = _reflectionUtil.GetIntegratedModuleCollection(context, integratedModeContext);
             IList  moduleConfigInfo      = _reflectionUtil.GetModuleConfigInfo();
             string name                  = "__ASP_IntegratedDynamicModule_Shim";
             string assemblyQualifiedName = typeof(IntegratedDynamicModule).AssemblyQualifiedName;
             string condition             = "managedHandler";
             moduleConfigInfo.Insert(0, _reflectionUtil.NewModuleConfigurationInfo(name, assemblyQualifiedName, condition));
             foreach (DynamicModuleRegistryEntry entry in DynamicEntries)
             {
                 moduleConfigInfo.Add(_reflectionUtil.NewModuleConfigurationInfo(entry.Name, entry.Type, "managedHandler"));
             }
             HttpModuleCollection registeredModuleCollection = _reflectionUtil.GetRegisteredModuleCollection(context);
             for (int i = 0; i < integratedModuleCollection.Count; i++)
             {
                 _reflectionUtil.AddModuleToCollection(registeredModuleCollection, integratedModuleCollection.GetKey(i), integratedModuleCollection.Get(i));
             }
             IList moduleList = _reflectionUtil.NewListOfModuleConfigurationInfo();
             for (int j = moduleConfigInfo.Count - DynamicEntries.Count; j < moduleConfigInfo.Count; j++)
             {
                 moduleList.Add(moduleConfigInfo[j]);
             }
             HttpModuleCollection modules3 = _reflectionUtil.BuildIntegratedModuleCollection(context, moduleList);
             for (int k = 0; k < modules3.Count; k++)
             {
                 _reflectionUtil.AddModuleToCollection(registeredModuleCollection, modules3.GetKey(k), modules3.Get(k));
             }
         }
     }
 }