Sys.Services.AuthenticationService.login(username, password, isPersistent, redirectUrl, customInfo, loginCompletedCallback, failedCallback, userContext);
Logout:注销用户的方法
Sys.Services.AutenticationService.set_defaultLoginCompletedCallback(value);
var defaultLoginCompletedCallback = Sys.services.AuthenticationService.get_defaultLoginCompletedCallback();
1
2
//登录按钮事件
3
function OnClickLogin()
4
{
5
Sys.Services.AuthenticationService.login(
6
document.form1.userId.value,
7
document.form1.userPwd.value,false,null,null,
8
OnLoginComplete, OnAuthenticationFailed,
9
"User context information.");
10
}
11
// 注销按钮事件
12
function OnClickLogout()
13
{
14
Sys.Services.AuthenticationService.logout(
15
null, OnLogoutComplete, OnAuthenticationFailed,null);
16
}
17
//注销完成调用的方法
18
function OnLogoutComplete(result,
19
userContext, methodName)
20
{}
21
22
//登录完成调用的方法
23
function OnLoginComplete(validCredentials,
24
userContext, methodName)
25
{
26
//如果验证成功
27
if(validCredentials == true)
28
{
29
DisplayInformation("欢迎你: " + document.form1.userId.value);//显示欢迎信息
30
LoadProfile();//加载个性化配置
31
// 隐藏不该显示的选择
32
GetElementById("loginId").style.visibility = "hidden";
33
GetElementById("setProfileProps").style.visibility = "visible";
34
GetElementById("logoutId").style.visibility = "visible";
35
}
36
else
37
{
38
DisplayInformation("没有登录");
39
}
40
}
41
42
//验证失败后调用的方法
43
function OnAuthenticationFailed(error_object,
44
userContext, methodName)
45
{
46
DisplayInformation("验证过程中发生如下错误: " +
47
error_object.get_message());
48
}
49
//加载个性化配置的方法-调用个性化服务的方法
50
function LoadProfile()
51
{
52
Sys.Services.ProfileService.load(null,
53
OnLoadCompleted, OnProfileFailed, null);
54
}
55
56
//保存个性化配置-调用个性化服务的方法
57
function SaveProfile()
58
{
59
Sys.Services.ProfileService.properties.Backgroundcolor =
60
GetElementById("bgcolor").value;//背景色
61
Sys.Services.ProfileService.properties.Foregroundcolor =
62
GetElementById("fgcolor").value; //前景色
63
Sys.Services.ProfileService.save(null,
64
OnSaveCompleted, OnProfileFailed, null);//保存
65
}
66
67
//读取个性配置并应用其内容
68
function OnLoadCompleted(numProperties, userContext, methodName)
69
{
70
document.bgColor =
71
Sys.Services.ProfileService.properties.Backgroundcolor;
72
document.fgColor =
73
Sys.Services.ProfileService.properties.Foregroundcolor;
74
}
75
//保存配置成功后调用的方法
76
function OnSaveCompleted(numProperties, userContext, methodName)
77
{
78
LoadProfile();//加载配置
79
//隐藏配置div
80
SetProfileControlsVisibility("hidden");
81
}
82
//配置加载失败时调用的方法
83
function OnProfileFailed(error_object, userContext, methodName)
84
{
85
alert("配置服务调用失败: " + error_object.get_message());
86
}
87
//设置个性化配置DIV是否显示
88
function SetProfileControlsVisibility(currentVisibility)
89
{
90
GetElementById("setProfileProps").style.visibility =
91
currentVisibility;
92
}
93
94
//显示消息的方法
95
function DisplayInformation(text)
96
{
97
document.getElementById('placeHolder').innerHTML +=
98
"<br/>"+ text;
99
}
100
//javascript的方法getElementById被封装成C#用法
101
function GetElementById(elementId)
102
{
103
var element = document.getElementById(elementId);
104
return element;
105
}
106
//判断是否正确加载了ajax类库
107
if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
108
109

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

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109
