在Form认证的网站下,我们要判断我们添加的权限是否存在.可以用下面的方法:
1
2
protected bool GetPermissions_Groups(string permissionsName)
3
{
4
try
5
{
6
string username = Context.User.Identity.Name;
7
PermissionsMoss.Permissions permService = new PermissionsMoss.Permissions();
8
permService.Url = SPControl.GetContextWeb(Context).Url + "/_vti_bin/Permissions.asmx";
9
System.Net.Cookie authCookie = GenerateFormsAuthenticationCookie.GetCookie(ConfigurationManager.AppSettings["username"], ConfigurationManager.AppSettings["userpass"]);
10
permService.CookieContainer = new CookieContainer();
11
permService.CookieContainer.Add(authCookie);
12
XmlNode ndPermissions = permService.GetPermissionCollection(SPControl.GetContextWeb(Context).Url, "Web");
13
14
XmlNodeList xnl = ndPermissions.ChildNodes;
15
16
if (xnl == null) return false;
17
foreach (XmlNode xn in xnl)
18
{
19
if (xn != null)
20
{
21
XmlNodeList xnl_permission = xn.ChildNodes;
22
23
foreach (XmlNode xn_permission in xnl_permission)
24
{
25
if (xnl_permission != null)
26
{
27
if (xn_permission.Attributes["MemberIsUser"].Value != "True")
28
{
29
if (xn_permission.Attributes["GroupName"].Value == permissionsName)
30
{
31
return true;
32
}
33
}
34
35
}
36
}
37
38
}
39
40
}
41
return false;
42
}
43
catch(Exception ex)
44
{
45
return false;
46
}
47
48
49
}
50

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50








































当然可以不用Webservies 直接用代码:
添加一个组及其给一个组权限并给组添加用户:





























































