请问
如何在 Global.asax 文件 Application_Start 中 利用 Session 实现全局对象?
又如何在其它页面中使用呢?

解决方案 »

  1.   

    用Cache才是全局,Session是用户会话
      

  2.   

    在Application_Start中你用Application[""]="";此时Session_start还没有执行了!
    他们的执行顺序是:1:Application_start  2: session_start ; 3:session_end: 4 Application_end.
    你具体想实现什么可贴出来研究下!
      

  3.   

    给你参考下    #region 加锁栏目    /// <summary>
        /// 加锁到某个栏目的页面
        /// </summary>
        /// <param name="pageID">栏目ID</param>
        public static void LockedColumn(int columnID)
        {
            Hashtable htLock = null;
            if (HttpContext.Current.Cache["LockedPageList"] != null)
            {
                htLock = (Hashtable)HttpContext.Current.Cache["LockedPageList"];            if (!htLock.ContainsKey(columnID))
                    htLock.Add(columnID, HttpContext.Current.User.Identity.Name);
            }
            else
            {
                htLock = new Hashtable();
                htLock.Add(columnID, HttpContext.Current.User.Identity.Name);
            }
            HttpContext.Current.Cache.Insert("LockedPageList", htLock, null,
                    System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromHours(2));
        }    /// <summary>
        /// 说明:清空某个用户的栏目锁
        /// 创建人:DC
        /// 创建时间:20071112
        /// 修改人:
        /// 修改时间:
        /// </summary>
        public static void RefreshCache()
        {
            if (HttpContext.Current.Cache["LockedPageList"] != null)
            {
                Hashtable ht = (Hashtable)HttpContext.Current.Cache["LockedPageList"];
                Hashtable htNew = new Hashtable();
                if (ht != null)
                {
                    htNew = (Hashtable)ht.Clone();
                    foreach (DictionaryEntry de in ht)
                    {
                        if (de.Value.ToString() == HttpContext.Current.User.Identity.Name)
                        {
                            htNew.Remove(de.Key);
                        }
                    }
                }
                HttpContext.Current.Cache["LockedPageList"] = htNew;
            }
        }
        #endregion
      

  4.   

    Database db2 = DatabaseManager.CreateDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source ="+MapPath("data\testdb1.mdb")+";","oledb");
    -----------------
    我想用这个实现全局变量,在其它页面可以用!