if(Session["UserName"]==null)
{
Response.Redirect(index.aspx);
}
怎么判断
两个人不能同时登陆一个帐户啊

解决方案 »

  1.   

    Session是服务器为客户端开辟的内存空间。所以不能用它来判断用户是否登陆,一般判断是否登陆的方法有两种。
    一是用户表中建立一个字段表明用户是否在线。在每次登陆或登出操作时修改它。
    还有就是把用户信息存在一些服务器公有内存中例如:application等中每次登陆时检查用户名,不存在就写入存在就提示。记得登出或Session失效时候删除该用户就可以了
      

  2.   

    点击登录按钮后调用以下方法:
    public void Login()
    {
    if(checkLogin())
    {
    string strUserName = this.txbUserName.Text.Trim();
    string strIP = Request.ServerVariables["REMOTE_ADDR"].ToString(); if(strUserName.Length == 0)
    Response.Write("<script language='javascript'>alert('请输入用户名!');</script>");
             else
             {
    Application[strUserName] = strUserName;
    Application[strUserName+"IP"] = strIP; Response.Write("<script language='javascript'>alert('登录成功!');</script>");
             }
           }
    }检查是否登录过:
    public bool checkLogin()
    {
    string strUserName = this.txbUserName.Text.Trim();
    string strIP = Request.ServerVariables["REMOTE_ADDR"].ToString(); if(Application[strUserName] != null)
    {
    if(Application[strUserName+"IP"].ToString() == strIP)
    {
    Response.Write("<script language='javascript'>alert('本机已经登录过了!');</script>");
    }
    else
    {
    Response.Write("<script language='javascript'>alert('已经在其他机器上登录了这个帐号!');</script>");
    }

    return false;
    } return true;
    }比较粗糙的一个实现,仅供参考。^_^