Asp.net中防止用户多次登录的方法
2008-03-07 16:04 liuqhui 阅读(270) 评论(0) 收藏 举报通过一个静态的实例list,每次系统登录的时候首先检查登录人loinguser是否在list中,如果loginuser不在list中,则将loginuser加到list中去。当Session超时或用户离开系统的时候,将其从list中删除
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
5
//===========================================
6
//File: LoginUserList.cs
7
//Date: 2007-12-10
8
//Author: liuqhui
9
//Desc: LoginUserList class
10
//============================================
11
12
namespace BLL
13
{
14
public class LoginUserList
15
{
16
private static LoginUserList _instance = new LoginUserList();
17
18
private IList<string> list = new List<string>();
19
20
private LoginUserList() { }
21
22
public static LoginUserList Instance{
23
get { return _instance; }
24
}
25
26
public bool AddUser(string name) {
27
if (list.Contains(name))
28
return false;
29
else {
30
list.Add(name);
31
32
return true;
33
}
34
}
35
36
public void RemoveUser(string name) {
37
list.Remove(name);
38
}
39
40
public void PurgeUsers() {
41
list.Clear();
42
}
43
}
44
}
45
using System;2
using System.Collections.Generic;3
using System.Text;4

5
//===========================================6
//File: LoginUserList.cs7
//Date: 2007-12-108
//Author: liuqhui9
//Desc: LoginUserList class10
//============================================11

12
namespace BLL13
{14
public class LoginUserList15
{16
private static LoginUserList _instance = new LoginUserList();17

18
private IList<string> list = new List<string>();19

20
private LoginUserList() { }21

22
public static LoginUserList Instance{23
get { return _instance; }24
}25

26
public bool AddUser(string name) {27
if (list.Contains(name))28
return false;29
else {30
list.Add(name);31

32
return true;33
}34
}35

36
public void RemoveUser(string name) {37
list.Remove(name);38
}39

40
public void PurgeUsers() {41
list.Clear();42
}43
}44
}45



浙公网安备 33010602011771号