In addition to the Sys.Services.AuthenticationService.login
function, the MicrosoftAjaxApplicationServices.js
script file includes a Sys.Services.AuthenticationService.logout
function. Like the Sys.Services.AuthenticationService.login
function, when calling the Sys.Services.AuthenticationService.logout
function you can supply a redirectUrl parameter and
callback functions to execute on success or failure.
In the downloadable demo, the master page displays a
"Log Out" link in the upper right corner for logged in users.
Clicking this "Log out" link executes the attemptLogout
function, which calls the Sys.Services.AuthenticationService.logout
function (see Listing 9).
Listing 9 - The attemptLogout function logs out the
user.
function attemptLogout(redirectUrl) {
Sys.Services.AuthenticationService.logout(
redirectUrl, // redirectUrl
null, // logoutCompletedCallback
null, // failedCallback
null); // userContext
}
As with the attemptLogin function,
the attemptLogout function accepts a redirectUrl input parameter, which is passed into the Sys.Services.AuthenticationService.logout function's redirectUrl input parameter. The net effect is that if a redirectUrl input parameter value is supplied to the attemptLogout function then the user is redirected to the
specified URL after successfully logging out. If this parameter value is not
provided then the current page the user is visiting is reloaded after logging
out.
When the "Log Out" link in the demo is clicked the
attemptLogout function is called without
specifying a redirectUrl input parameter. Consequently,
the page the user is visiting when logging out is reloaded after log off. However,
you could modify this script so that the user is redirected to a particular
page upon log off.