如何在 Global.asax 文件 Application_Start 中 利用 Session 实现全局对象? 请问如何在 Global.asax 文件 Application_Start 中 利用 Session 实现全局对象?又如何在其它页面中使用呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用Cache才是全局,Session是用户会话 在Application_Start中你用Application[""]="";此时Session_start还没有执行了!他们的执行顺序是:1:Application_start 2: session_start ; 3:session_end: 4 Application_end.你具体想实现什么可贴出来研究下! 给你参考下 #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 Database db2 = DatabaseManager.CreateDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source ="+MapPath("data\testdb1.mdb")+";","oledb");-----------------我想用这个实现全局变量,在其它页面可以用! asp.net 如何屏蔽迅雷、快车等主流下载软件 AutoCompleteExtender在提示框被遮住,如何解决? 引用 ASP.NET中的Eval()和DataBinder.Eval()方法 Session属于哪种身份验证? 100分求一条sql语句。。。关于行列转换查询的。。。 oa办公系统 上海盈佳网络招聘.NET精英 帮我看看!!!! 怎么使新打开的窗口不显示浏览器地址栏工具栏等(只显示窗体内容) 在IIS中不能浏览*.aspx的问题? 如何防止页面刷新后绑定在下拉列表框中的值不丢失? 字符串组合的控件id的问题
他们的执行顺序是:1:Application_start 2: session_start ; 3:session_end: 4 Application_end.
你具体想实现什么可贴出来研究下!
/// 加锁到某个栏目的页面
/// </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
-----------------
我想用这个实现全局变量,在其它页面可以用!