Sys.Services.ProfileService 类

更新:2007 年 11 月

为配置文件服务提供客户端代理类。

命名空间:Sys.Services

**继承:**无

成员

名称

说明

Sys.Services.ProfileService 构造函数

初始化 Sys.Services.ProfileService 类的新实例。

Sys.Services ProfileService DefaultWebServicePath 字段

指定默认配置文件服务的路径。

Sys.Services ProfileService properties 字段

包含配置文件信息。

Sys.Services ProfileService load 方法

加载指定的配置文件属性。

Sys.Services ProfileService save 方法

保存指定的配置文件属性。

Sys.Services ProfileService defaultFailedCallback 属性

获取或设置默认的失败回调函数。

Sys.Services ProfileService defaultLoadCompletedCallback 属性

获取或设置默认的加载完成回调函数。

Sys.Services ProfileService defaultSaveCompletedCallback 属性

获取或设置默认的保存完成回调函数的名称。

Sys.Services ProfileService defaultSucceededCallback 属性

获取或设置服务的默认成功回调函数。

Sys.Services ProfileService defaultUserContext 属性

获取或设置服务的默认用户上下文。

Sys.Services ProfileService path 属性

获取或设置配置文件服务路径。

Sys.Services ProfileService timeout 属性

获取或设置配置文件服务超时值。

备注

通过 ProfileService 类,可以对用户的配置文件信息进行脚本访问。该类调用配置文件服务的方法所用的基础结构与调用任何其他 Web 服务方法所用的基础结构一样。

说明:

内置配置文件服务位于服务器上的预定义位置。

Profile 类为单一实例;它只有一个提供全局访问点的实例。它始终对应用程序可用,因此无需将其实例化。

示例

说明

下面的示例演示如何使用 ProfileService 类来获取当前已验证身份的用户的配置文件信息。有关更多信息,请参见将配置文件信息与 ASP.NET AJAX 一起使用

代码

// The OnClickLogin function is called when 
// the user clicks the Login button. 
// It calls the AuthenticationService.login to
// authenticates the user.
function OnClickLogin()
{
    Sys.Services.AuthenticationService.login(
        document.form1.userId.value,
        document.form1.userPwd.value,false,null,null,
        OnLoginComplete, AuthenticationFailedCallback,
        "User context information.");
}


// The OnClickLogout function is called when 
// the user clicks the Logout button. 
// It logs out the current authenticated user.
function OnClickLogout()
{
    Sys.Services.AuthenticationService.logout(
        null, OnLogoutComplete, AuthenticationFailedCallback,null);
}


function OnLogoutComplete(result, 
    userContext, methodName)
{
    // Code that performs logout 
    // housekeeping goes here.          
}       

// This function is called after the user is
// authenticated. It loads the user's profile.
// This is the callback function called 
// if the authentication completed successfully.
function OnLoginComplete(validCredentials, 
    userContext, methodName)
{
    if(validCredentials == true)
    {
        DisplayInformation("Welcome " + document.form1.userId.value);
    
        // Set the default failed callback function.
        DefaultFailedCallback();
        
        // Set the default load callback function.
        DefaultLoadCompletedCallback();
        
        // Set the default save callback function.
        DefaultSaveCompletedCallback();
        
        // Get path and timeout
        GetPathAndTimeout();
        
        
        LoadProfile();
        
    
        // Hide or make visible page display elements.
        GetElementById("loginId").style.visibility = "hidden";
        GetElementById("setProfProps").style.visibility = "visible";
        GetElementById("logoutId").style.visibility = "visible";
    
    }
    else
    {
        DisplayInformation("Could not login");
    }
}


// This is the callback function called 
// if the authentication failed.
function AuthenticationFailedCallback(error_object, 
    userContext, methodName)
{   
    DisplayInformation("Authentication failed with this error: " +
        error_object.get_message());
}



// Gets the profile service path and timeout.
function GetPathAndTimeout()
{
    // Get the profile service path
    var path = Sys.Services.ProfileService.get_path();

    if (path == "")
        path = "standard default path";

    alert("The profile service path is: " + path);

    // Get the profile service timeout
    var timeout = Sys.Services.ProfileService.get_timeout();

    alert("The profile service timeout is: " + timeout);

}

// Sets and gets the default load completed callback function.
function DefaultLoadCompletedCallback()
{
       

    // Set default load completed callback function.
    Sys.Services.ProfileService.set_defaultLoadCompletedCallback(LoadCompletedCallback);

     // Get default load completed callback function.
    var defaultLoadCompletedCallback =
        Sys.Services.ProfileService.get_defaultLoadCompletedCallback();
           

    alert("The default load completed callback is: " + 
        defaultLoadCompletedCallback);

}

// Sets and gets the default save completed callback function.
function DefaultSaveCompletedCallback()
{

    // Set default load completed callback function.
    Sys.Services.ProfileService.set_defaultSaveCompletedCallback(SaveCompletedCallback);

     // Get default save completed callback function.
    var defaultSaveCompletedCallback =
        Sys.Services.ProfileService.get_defaultSaveCompletedCallback();


    alert("The default save completed callback is: " + 
        defaultSaveCompletedCallback);

}
// Sets and gets the default failed callback function.
function DefaultFailedCallback()
{
       
    // Set default failed callback function.
    Sys.Services.ProfileService.set_defaultFailedCallback(ProfileFailedCallback);

     // Get default failed callback function.
    var defaultFailedCallback =
        Sys.Services.ProfileService.get_defaultFailedCallback();       


    alert("The default failed callback is: " + defaultFailedCallback);

}


// Loads the profile of the current
// authenticated user.
function LoadProfile()
{
    Sys.Services.ProfileService.load(null, 
        LoadCompletedCallback, ProfileFailedCallback, null);

}

// Saves the new profile
// information entered by the user.
function SaveProfile()
{
       
    Sys.Services.ProfileService.properties.Backgroundcolor = 
        GetElementById("bgcolor").value;
    
    Sys.Services.ProfileService.properties.Foregroundcolor =
        GetElementById("fgcolor").value; 

       
    Sys.Services.ProfileService.save(null, 
        SaveCompletedCallback, ProfileFailedCallback, null);

}

// Reads the profile information and displays it.
function LoadCompletedCallback(numProperties, userContext, methodName)
{
    document.bgColor = 
        Sys.Services.ProfileService.properties.Backgroundcolor;

    document.fgColor =   
        Sys.Services.ProfileService.properties.Foregroundcolor;         
}



// This is the callback function called 
// if the profile was saved successfully.
function SaveCompletedCallback(numProperties, userContext, methodName)
{
    LoadProfile();
    // Hide the area that contains 
    // the controls to set the profile properties.
    SetProfileControlsVisibility("hidden");
}

// This is the callback function called 
// if the profile load or save operations failed.
function ProfileFailedCallback(error_object, userContext, methodName)
{
    alert("Profile service failed with message: " + 
            error_object.get_message());
}


// Utility functions.

// This function sets the visibilty for the
// area containing the page elements for settings
// profiles.
function SetProfileControlsVisibility(currentVisibility)
{
    GetElementById("setProfileProps").style.visibility = 
        currentVisibility; 
}

// Utility function to display user's information.
function DisplayInformation(text)
{
    document.getElementById('placeHolder').innerHTML += 
    "<br/>"+ text;
}


function GetElementById(elementId)
{
    var element = document.getElementById(elementId);
    return element;
}

请参见

概念

Sys.Services.AuthenticationService 类

Sys.Net.WebServiceProxy 类

将配置文件信息与 ASP.NET AJAX 一起使用

参考

Sys.Services.ProfileGroup 类