解决思路:
维护一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();
}
{
// 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();
}当用户登录时,online设置为在线状态(true),下线时设置为离线状态(false).
建立global.asa在根目录下.利用session_onEnd事件,设置离线状态.
<script language="vbscript" runat="server">
sub Application_OnStart
Application("online") = 0
set Application("cn") = Server.CreateObject("ADODB.Connection")
Application("db") = Server.MapPath("bbs/note/note.mdb")
Application("cn").Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Application("db")
end sub
sub Application_OnEnd
Application("onlinde") = 0
end sub
sub Session_OnStart
end sub
sub Session_OnEnd
if Session("pass") then
Application("online") = Application("online") - 1
Application("cn").execute("update user_info set online = false where UID = "&session("UID"))
end if
end Sub
</script>
sub Application_OnStart
Application("online") = 0
set Application("cn") = Server.CreateObject("ADODB.Connection")
Application("db") = Server.MapPath("bbs/note/note.mdb")
Application("cn").Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Application("db")
end sub
sub Application_OnEnd
Application("onlinde") = 0
end sub
sub Session_OnStart
end sub
sub Session_OnEnd
if Session("pass") then
Application("online") = Application("online") - 1
Application("cn").execute("update user_info set online = false where UID = "&session("UID"))
end if
end Sub
</script>
浙公网安备 33010602011771号