次の方法で共有


Sys.Services.ProfileService Class

Provides the client proxy class for the profile service.

Namespace: Sys.Services

Inherits: None

Members

Name

Description

Sys.Services.ProfileService Constructor

Initializes a new instance of the Sys.Services.ProfileService class.

Sys.Services ProfileService DefaultWebServicePath Field

Specifies the path of the default profile service.

Sys.Services ProfileService properties Field

Contains the profile information.

Sys.Services ProfileService load Method

Loads the specified profile properties.

Sys.Services ProfileService save Method

Saves the specified profile properties.

Sys.Services ProfileService defaultFailedCallback Property

Gets or sets the default failure callback function.

Sys.Services ProfileService defaultLoadCompletedCallback Property

Gets or sets the default load-completed callback function.

Sys.Services ProfileService defaultSaveCompletedCallback Property

Gets or sets the name of the default save-completed callback function.

Sys.Services ProfileService defaultSucceededCallback Property

Gets or sets the default succeeded callback function for the service.

Sys.Services ProfileService defaultUserContext Property

Gets or sets the default user context for the service.

Sys.Services ProfileService path Property

Gets or sets the profile service path.

Sys.Services ProfileService timeout Property

Gets or sets the profile service time-out value.

Remarks

The ProfileService class provides script access to a user's profile information. It calls methods of the profile service through the same infrastructure used to call any other Web service method.

Note

The built-in profile service is located on the server in a predefined location.

The Profile class is a singleton; it has only one instance that provides a global point of access. It is always available to your application and you do not have to instantiate it.

Example

Description

The following example shows how to use the ProfileService class to obtain profile information for the currently authenticated user. For more information, see Using Profile Information with Microsoft Ajax.

Code

// 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;
}
    

See Also

Reference

Sys.Services.ProfileGroup Class

Concepts

Sys.Services.AuthenticationService Class

Sys.Net.WebServiceProxy Class

Using Profile Information with Microsoft Ajax