维护一Online表,查看有登录,就不允许再次登录,以Sessionid作为唯一标识符号,也可以产生一个GUID发到COOKIE中,以区分不同的CLIENT,再加上JS,可以达到更好的效果,比如离开后自动离线。
解决代码如下:
public virtual void Application_Start(object sender, EventArgs e)
{
// reset the mailer indicator
Application["MailerStatus"] = "All Mailings Complete";
// initialize a datatable for users online
DataTable objUserTable = new DataTable();
objUserTable.Columns.Add("SessionID",System.Type.GetType("System.Guid"));
objUserTable.Columns.Add("PeopleID",System.Type.GetType("System.Int32"));
objUserTable.Columns.Add("ShowDetail",System.Type.GetType("System.Boolean"));
DataColumn[] pk = new DataColumn[1];
pk[0] = objUserTable.Columns[0];
objUserTable.PrimaryKey = pk;
Application["UserTable"] = objUserTable;
}
/**////
/// The Session_Start event adds user session information to
/// Application["UserTable"].
///
public virtual void Session_Start(object sender, EventArgs e)
{
Application.Lock();
//Application.Lock ();
DataTable objUserTable = (DataTable)Application["UserTable"];
DataRow objRow = objUserTable.NewRow();
Guid objGuid = Guid.NewGuid();
objRow[0] = objGuid;
Session["PfSessionID"] = objRow[0];
objRow[1] = 0;
objRow[2] = false;
objUserTable.Rows.Add(objRow);
Application["UserTable"] = objUserTable;
Application.UnLock();
}
/**////
/// The Session_End event deletes user session information from
/// Application["UserTable"].
///
public virtual void Session_End(object sender, EventArgs e)
{
Application.Lock();
DataTable objUserTable = (DataTable)Application["UserTable"];
objUserTable.Rows.Find((Guid)Session["PfSessionID"]).Delete();
Application["UserTable"] = objUserTable;
Application.UnLock();
} |
关键词:
【推荐给好友】【关闭】
最新五条评论
查看全部评论
评论总数 0 条
您的评论
·用户发表意见仅代表其个人意见,并且承担一切因发表内容引起的纠纷和责任
·本站管理人员有权在不通知用户的情况下删除不符合规定的评论信息或留做证据
·请客观的评价您所看到的资讯,提倡就事论事,杜绝漫骂和人身攻击等不文明行为
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有