如何防止控制客户端使其用同一帐户重复登录系统.
解决思路:
维护一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();
}
