验证模式为Form问题如题

解决方案 »

  1.   

    save username in some place while the user login.
    then try to check wether the user is online before another one try to login.
      

  2.   

    such as session,but too waste of memory .
      

  3.   

    可以考虑在数据库加一个 在线 字段..   
    或者用application 变量 登陆后 用登陆名保存一个值, 在登陆的时候检测一下.
      

  4.   

    保留第一个 登录者的IP,在其它IP登录就提示用户已登录
      

  5.   

    登录后可以生成个随机数保存到SESSION和数据库中,每次请求页面时候后台判断二者是否同
      

  6.   

    if you must control that when the user leave, you could choose session.
    if you choose database,you will hardly to control the user's leaving.
      

  7.   

    网上的一个办法记录SessionID和Session["Name"]当登陆时写进这两个值如果是第二次登陆时会有不同的SessionID,此时可对前面的帐号做一些动作:例如:自动下线(这种做法就是自动踢前面的人,使之不能同时在线)
      

  8.   

    用数据库存session 记录在线用户通过登录页面 判断是否已有相同用户登录即可
      

  9.   

    不好意思没有及时回复大家。
    做这个需求时,确实要求要做到能监控到用户的退出,所以根据大家提供的办法,决定先采用“NqIceCoffee(进步于细节中) ”试试,看是否能达到预期的效果
      

  10.   

    在实验室这个需求时,遇到一个问题,请大侠们赐教,代码位于Global.asax中,如下所示:
    protected void Session_End(Object sender, EventArgs e)
       {
    //当Session失效时,删除对应的登录用户数据
    try
    {
         PublicFunction.DelLoginUser("",Session.SessionID,(Page)sender);
    }
    catch(Exception ex)
    {
         PublicFunction.MessageBox((Page)sender,ex.Message);
    }
    }问题:为何执行DelLoginUser时,系统会出现异常?
    DelLoginUser函数代码为:
    public static void DelLoginUser(string strUserName,string strSessionID,Page objPage)
    {
         string strSql = "";
         if(strSessionID == "")
         {
    strSql = "Delete from tbl_UserOnline where UserName='"+strUserName+"'";
          }
         else
         {
             strSql = "Delete from tbl_UserOnline where SessionID='"+strSessionID+"'";
          }     SqlCommand objComm = new SqlCommand(strSql,DBConnection(objPage));
         objComm.ExecuteNonQuery();
    }
      

  11.   

    要防止同一用户同时登陆,首页应该记录在线用户的信息(这里与用户名为例),然后判断正在登陆的用户里面是否已存在。在这里使用一个cache存放已经登陆的用户名,但是还有一个问题就是要知道用户是什么时候离开系统的呢?这就要定期清除cache中的内容了,也就是设置一个cache的时间。这个时间可以跟用户的session值联系起来,刚好当用户session值失效的时候该用户在cache里面的信息也会被清空.这样就达到了防止同时登陆的效果,具体代码如下:   放在登陆成功的地方:string key = TextBox1.Text; //用户名文本框设为cache关键字 
    string uer = Convert.ToString(Cache[key]); //读取cache中用户相应的值
    //判断cache中是否有用户的信息,如果没有相关的值,说明用户未登陆
    if (uer == null || uer == String.Empty)
    {
     //定义cache过期时间 TimeSpan SessTimeout = new TimeSpan(0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0); //第一次登陆的时候插入一个用户相关的cache值,
     HttpContext.Current.Cache.Insert(key, key, null, DateTime.MaxValue, SessTimeout, System.Web.Caching.CacheItemPriority.NotRemovable, null);
     Session["ADMINID"] = TextBox1.Text;
     Response.Redirect("main.aspx");
    }
    else
    {
     //重复登陆
     Response.Write("<script>alert('您的账号已经登陆!');window.location='login.aspx';</script>");

    声明:转载
      

  12.   

    使用Hashtable表在:Global.asax
        Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
            ' 在应用程序启动时运行的代码        Dim Table As Hashtable = New Hashtable '新哈希表
            Application("UserVisite") = Table
            
        End Sub
    在页面程序 LOGON        '用户登陆程序
            ......
            Dim Table As Hashtable = Application("UserVisite")
            Dim HashtableKey As String = UserID '用户ID  哈希表KEY
            If Table.Contains(HashtableKey) = True Then '在哈希表内存在
                Table(HashtableKey) = Session.SessionID
            Else
                Table.Add(HashtableKey, Session.SessionID)
            End If以后每个页面判断
            Dim Table As Hashtable = Application("UserVisite")
            Dim HashtableKey As String = UserID '用户ID
            If Table(HashtableKey).ToString().Equals(Session.SessionID) = False Then
               '强制退出,清楚SESSION 
               Session.Abandon()
            End If