Session_End执行时候,该函数内部Session还可以访问到嚒
我要用Session来统计用户登录系统到停止操作的在线时间
登录时候
HttpContext.Current.Session["UserName"]=Username;
HttpContext.Current.Session["LoginTime"]=DateTime.Parse(DateTime.Now.ToString());
Session失效时候,不是可以触发Session_End执行
protected void Session_End(Object sender, EventArgs e)
{
if(Session["UserName"]!=null && Session["LoginTime"]!=null)
{
HNCCIC.DAL.DA_UserLogin UserLogin = new HNCCIC.DAL.DA_UserLogin();
TimeSpan Duretime= DateTime.Parse(DateTime.Now.ToString())- DateTime.Parse(Session["LoginTime"].ToString());
UserLogin.UpdateOnlineTime(Session["UserName"].ToString(),Convert.ToDouble(Duretime.TotalMinutes));//将在线时间差更新到数据库
Session["UserName"]=null;
Session["LoginTime"]=null;
}
}
大家觉得这个方案可行嚒
还有没有更好的办法