Ajax.net中的Web服务

Login:用来登陆的方法
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//登录按钮事件
  3function 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// 注销按钮事件
 12function OnClickLogout()
 13{
 14    Sys.Services.AuthenticationService.logout(
 15        null, OnLogoutComplete, OnAuthenticationFailed,null);
 16}

 17//注销完成调用的方法
 18function OnLogoutComplete(result, 
 19    userContext, methodName)
 20{}        
 21
 22//登录完成调用的方法
 23function 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//验证失败后调用的方法
 43function OnAuthenticationFailed(error_object, 
 44    userContext, methodName)
 45{    
 46    DisplayInformation("验证过程中发生如下错误: " +
 47        error_object.get_message());
 48}

 49//加载个性化配置的方法-调用个性化服务的方法
 50function LoadProfile()
 51{
 52    Sys.Services.ProfileService.load(null
 53        OnLoadCompleted, OnProfileFailed, null);
 54}

 55
 56//保存个性化配置-调用个性化服务的方法
 57function 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//读取个性配置并应用其内容
 68function 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//保存配置成功后调用的方法
 76function OnSaveCompleted(numProperties, userContext, methodName)
 77{
 78    LoadProfile();//加载配置
 79    //隐藏配置div
 80    SetProfileControlsVisibility("hidden");
 81}

 82//配置加载失败时调用的方法
 83function OnProfileFailed(error_object, userContext, methodName)
 84{
 85    alert("配置服务调用失败: " + error_object.get_message());
 86}

 87//设置个性化配置DIV是否显示
 88function SetProfileControlsVisibility(currentVisibility)
 89{
 90    GetElementById("setProfileProps").style.visibility = 
 91        currentVisibility; 
 92}

 93
 94//显示消息的方法
 95function DisplayInformation(text)
 96{
 97    document.getElementById('placeHolder').innerHTML += 
 98    "<br/>"+ text;
 99}

100//javascript的方法getElementById被封装成C#用法  
101function GetElementById(elementId)
102{
103    var element = document.getElementById(elementId);
104    return element;
105}

106//判断是否正确加载了ajax类库
107if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
108
109
posted @ 2007-11-14 19:57  子午  阅读(253)  评论(0编辑  收藏  举报