Класс Sys.Services.ProfileService

Обновлен: Ноябрь 2007

Представляет собой клиентский класс прокси для службы профиля.

Пространство имен: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 предоставляет доступ сценария к сведениям профиля пользователя. Он вызывает методы службы профиля с помощью одной и той же инфраструктуры, используемой для вызова любого другого метода веб-службы.

Bb383800.alert_note(ru-ru,VS.90).gifПримечание.

Встроенная служба профиля находится в предопределенном расположении на сервере.

Класс 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