保证账号在线唯一性
用户登陆时,调用 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![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
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是否为空,检测状态,是否在别处登陆
120
119
121
120 }
122
121}
123
122
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
34
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
35
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
36
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
38
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
39
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
40
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
42
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
43
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
44
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
45
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
46
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
47
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
48
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
49
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
50
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
51
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
52
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
53
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
54
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
55
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
56
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
57
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
58
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
59
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
60
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
61
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
62
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
63
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
64
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
65
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
66
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
67
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
68
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
69
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
70
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
71
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
72
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
73
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
74
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
75
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
76
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
77
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
78
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
79
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
80
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
120
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
121
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
122
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
123
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)