Skip to main content

For IE browsers only, you can use the following javascript to logout the user if using Windows Authentication. Note that closing the browser isn't required, but recommended since the user might be using a non-IE browser. If the user selects "No" (to close the browser), they will be prompted for credentials again.

/**
 * ASP.NET Windows Authentication Logout
 *
 * For IE browsers only!
 *
 * For IE browsers only, you can use the following javascript to logout the user
 * if using Windows Authentication. (Note: closing the browser isn't required,
 * but recommended since the user might be using a non-IE browser).
 *
 * If the user clicks "No" to close the browser, then the user will be prompted
 * for a username/password if they attempt to access a page on the site that
 * requires authentication.
 *
 * NOTE: It's also worth pointing out that the "ClearAuthenticationCache"
 * command clears ALL authentication data, not just for the site which requested
 * it.
 *
 * http://stackoverflow.com/a/5731523
 */
function logOut() {
    try {
        document.execCommand("ClearAuthenticationCache");
    } catch (e) {}
    window.close();
}