思路:
一.登陸時為每個用戶保存一個唯一ID號,處理頁判斷ID異同。代碼:
登陸頁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
<stringstring> userlist = Cache["userlist"as System.Collections.Generic.Dictionary<stringstring>;
            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<stringstring>)[Session["name"].ToString()]!= Session.SessionID)
            Response.Write(
"<script>alert('已经有相同帐号登陆');location.href='login.aspx';</script>");

    }

二.用戶表加登陸次數列,登陸時查詢用戶登錄次數並保存到COOKIE,處理頁查詢登陸次數並與COOKIE比較,不一致説明已被踢出。

-- =============================================
-- Author:    Caviare 
-- Create date:    2006/4/13
-- Description:    查詢目前使用者的登入的SESSION ID
--              讓系統能夠防止使用者重複登入
-- =============================================
CREATE PROCEDURE [dbo].[SP_GET_SESSION_ID] 
    -- Add the parameters for the stored procedure here
     @ACCOUNT VARCHAR(20),        --要查詢的帳號 
    @SESSION  int output          --登入次數
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
 
   set @SESSION=0  --登入次數的預設值

  
       select @SESSION=isnull(SESSION,0)
              from dbo.BSS_USER_DATA 
              where  ACCOUNT_ID=@ACCOUNT   -- and  PASSWORD=@PASSWORD
    set @SESSION =isnull(@SESSION,0)
   
  
END
GO
posted on 2007-04-27 15:00  Caviare  阅读(249)  评论(0编辑  收藏  举报