semye-静心

积累,点点滴滴
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

请高手指点

Posted on 2007-01-31 16:45  semye  阅读(403)  评论(5编辑  收藏  举报
 保证账号在线唯一性

         用户登陆时,调用 UserOnline.cs 中的方法 SetOnLine(string sAccount),在内存表中记录在线用户(用Hashtable的一个键/值对)。在各个功能页面调用UserOnline.cs中的方法checkRight(string User_Account,string onlineID,string IP),页面将近100个,所以我要调用将近100遍,这项任务原来就已做完,但原来没写日志,方法checkRight()只有string User_Account,string onlineID两个参数,今天加日志时,要用到IP地址,所以又加了 string IP 这个参数,这一加又要将近一百遍!实在郁闷,所以想请问大家,像这种保证用户唯一登陆的,还有没有些其它办法?

以下贴出文件UserOnline.cs

  1
  2  1using System;
  3  2using System.Data;
  4  3using System.Collections;
  5  4using com.meiyaonline.airprice.DAL;
  6  5using System.Text;
  7  6namespace com.meiyaonline.airprice.tktprice.BLL
  8  7{
  9  8    /**//// <summary>
 10  9    /// UserOnLine 的摘要说明。
 11 10    /// </summary>
 12 11    public class UserOnLine
 13 12    {
 14 13        public UserOnLine()
 15 14        {
 16 15            //
 17 16            // TODO: 在此处添加构造函数逻辑
 18 17            //
 19 18        }

 20 19        public static Hashtable hs = new Hashtable();
 21 20        /**//// <summary>
 22 21        /// 在内存中记录在线用户
 23 22        /// </summary>
 24 23        /// <param name="sAccount">用户账号</param>
 25 24        /// <returns>在线用户的临时ID</returns>
 26 25        public static string SetOnLine(string sAccount)
 27 26        {
 28 27            int nCount = hs.Count;
 29 28            string sAccountUpper = sAccount.ToUpper();
 30 29            string sID=Guid.NewGuid().ToString();
 31 30            if(hs.ContainsKey(sAccountUpper))
 32 31            {
 33 32                hs[sAccountUpper] = sID;
 34 33                
 35 34            }

 36 35            else
 37 36            {
 38 37                hs.Add(sAccountUpper,sID);
 39 38            }
            
 40 39            return sID;
 41 40        }

 42 41        /**//// <summary>
 43 42        /// 检测用户的在线临时ID
 44 43        /// </summary>
 45 44        /// <param name="sAccount">用户账号</param>
 46 45        /// <param name="sID">在线临时ID</param>
 47 46        /// <returns>该用户是否有效</returns>
 48 47        public static bool CheckOnLine(string sAccount,string sID)
 49 48        {
 50 49            string sAccountUpper = sAccount.ToUpper();
 51 50            try
 52 51            {
 53 52                if(sID!=hs[sAccountUpper].ToString())
 54 53                {return true;}
 55 54                else
 56 55                {return false;}
 57 56            }

 58 57            catch
 59 58            {return true;}
 60 59        }

 61 60        /**//// <summary>
 62 61        /// 检测SESSION
 63 62        /// </summary>
 64 63        /// <param name="sSession"></param>
 65 64        /// <param name="?"></param>
 66 65        /// <returns>session是否为空</returns>
 67 66        public static bool CheckOnSession(object  sSession)
 68 67        {
 69 68            if(sSession.ToString()=="")
 70 69            {
 71 70//                com.meiyaonline.airprice.tktprice.BLL.login.DailyRecode();
 72 71                return true;
 73 72            }

 74 73            else
 75 74            {
 76 75                return false;
 77 76            }

 78 77            
 79 78        }

 80 79        检测session是否为空,检测状态,是否在别处登陆检测session是否为空,检测状态,是否在别处登陆
120119
121120    }

122121}

123122