private void DelSession()
{
string SessionAD;
SessionAD = Session["AD"].ToString ().Trim () ;//从程序中获得个人信息的AD号
DbConn conn = new DbConn () ;
string strSql = "delete from online_user where AD='" + SessionAD + "'";
OleDbConnection con = conn.connection () ;
OleDbCommand cmd = new OleDbCommand (strSql,con) ;
cmd.ExecuteNonQuery () ;
con.Close();
} private void Login_Click(object sender, System.EventArgs e)
{
DelSession();//点击重登陆连接可以删除数据库个人AD信息
Session.Abandon () ;
// Response.Cookies["UserAD"].Values.Clear () ;
Response.Cookies["UserAD"].Expires = DateTime.Now .AddHours (-1) ;
string strInServerPath = Request.ApplicationPath ;
// Response.Write (strInServerPath) ;
Response.Redirect (strInServerPath + "index.aspx") ;
} private void Exit_Click(object sender, System.EventArgs e)
{
DelSession();//点击重登陆连接可以删除数据库个人AD信息
Session.Abandon () ;
string strInServerPath = Request.ApplicationPath ;
Response.Redirect (strInServerPath + "sys_message/sys_message.aspx?id=45") ;
}
我在USER登陆的时候将user的userID写入了数据库,当user退出的时候,重登陆的时候将数据库userid删除,就是关闭浏览器的时候,userid并不能删除,请给我一个方案,在session上做文章不知道可以否?
{
string SessionAD;
SessionAD = Session["AD"].ToString ().Trim () ;//从程序中获得个人信息的AD号
DbConn conn = new DbConn () ;
string strSql = "delete from online_user where AD='" + SessionAD + "'";
OleDbConnection con = conn.connection () ;
OleDbCommand cmd = new OleDbCommand (strSql,con) ;
cmd.ExecuteNonQuery () ;
con.Close();
} private void Login_Click(object sender, System.EventArgs e)
{
DelSession();//点击重登陆连接可以删除数据库个人AD信息
Session.Abandon () ;
// Response.Cookies["UserAD"].Values.Clear () ;
Response.Cookies["UserAD"].Expires = DateTime.Now .AddHours (-1) ;
string strInServerPath = Request.ApplicationPath ;
// Response.Write (strInServerPath) ;
Response.Redirect (strInServerPath + "index.aspx") ;
} private void Exit_Click(object sender, System.EventArgs e)
{
DelSession();//点击重登陆连接可以删除数据库个人AD信息
Session.Abandon () ;
string strInServerPath = Request.ApplicationPath ;
Response.Redirect (strInServerPath + "sys_message/sys_message.aspx?id=45") ;
}
我在USER登陆的时候将user的userID写入了数据库,当user退出的时候,重登陆的时候将数据库userid删除,就是关闭浏览器的时候,userid并不能删除,请给我一个方案,在session上做文章不知道可以否?
而是等到设定的时间之后
因为在user登陆的时候已经把这些user的id写入了数据库,现在想在服务器端找到这些session值,然后和开始登陆时候的数据记录做比较,然后他们一致的时候就把这边sessionid删掉
客户端关闭页面也不能完全准确的能做到及时把服务端Session销毁掉!单纯的用关闭页面的事件也不是很准确,因为如果客户端同时打开了多个页面的话,而只关闭其中一个,这样把服务端Session销毁就会造成客户端其他页面的Session值丢失。如果到服务器端查询的话要把服务器上的每个SessionID和数据库中的进行比较才能确定究竟是哪些Session已经过期,过期的就删掉。何况Session的生命期是服务器端设置好的,只有等到生命期结束才自动销毁。
http://www.pconline.com.cn/pcedu/empolder/net/asp/0507/656046.html这有一个例,大家一起研究一下,我先写一个看看
Global.asax.cs
private void InitOnline()
{
//***************************************************************
// 在线情况监控部分 // 放入全局性变量 Application["Online"]
Application["Online"] = new OnlineData(); //***************************************************************
}protected void Session_End(Object sender, EventArgs e)
{
Application["Count"] = int.Parse(Application["Count"].ToString()) - 1; //***************************************************************
// 在线情况监控部分 OnlineServer.DeleteSession(
System.Web.HttpContext.Current.Session.SessionID); //*************************************************************** }
通过System.Web.HttpContext.Current.Session.SessionID可以取到当前用户的SessionID号,然后写代码删除这个SESSION的记录就行了。
http://community.csdn.net/Expert/topic/4151/4151257.xml?temp=.896084
http://www.webdiyer.com