login.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
Session["name"] = TextBox1.Text;
if (Cache["userlist"] == null)
{
System.Collections.Generic.Dictionary<string,string> userlist = new System.Collections.Generic.Dictionary<string,string>();
userlist.Add(Session["name"].ToString(), Session.SessionID);
Cache["userlist"] = userlist;
}
else
{
System.Collections.Generic.Dictionary<string, string> userlist = Cache["userlist"] as System.Collections.Generic.Dictionary<string, string>;
userlist[Session["name"].ToString()] = Session.SessionID;
Cache["userlist"] = userlist;
}
Response.Redirect("default.aspx");
}
{
Session["name"] = TextBox1.Text;
if (Cache["userlist"] == null)
{
System.Collections.Generic.Dictionary<string,string> userlist = new System.Collections.Generic.Dictionary<string,string>();
userlist.Add(Session["name"].ToString(), Session.SessionID);
Cache["userlist"] = userlist;
}
else
{
System.Collections.Generic.Dictionary<string, string> userlist = Cache["userlist"] as System.Collections.Generic.Dictionary<string, string>;
userlist[Session["name"].ToString()] = Session.SessionID;
Cache["userlist"] = userlist;
}
Response.Redirect("default.aspx");
}
default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (Session["name"] == null)
Response.Write("<script>alert('请登陆');location.href='login.aspx';</script>");
else if((Cache["userlist"] as System.Collections.Generic.Dictionary<string, string>)[Session["name"].ToString()]!= Session.SessionID)
Response.Write("<script>alert('已经有相同帐号登陆');location.href='login.aspx';</script>");
}
{
if (Session["name"] == null)
Response.Write("<script>alert('请登陆');location.href='login.aspx';</script>");
else if((Cache["userlist"] as System.Collections.Generic.Dictionary<string, string>)[Session["name"].ToString()]!= Session.SessionID)
Response.Write("<script>alert('已经有相同帐号登陆');location.href='login.aspx';</script>");
}