如何防止控制客户端使其用同一帐户重复登录系统.

解决思路:

维护一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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值