Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FormsAuthentication.SignOut() using javascript

Does anyone please help me for solving this issue, In my asp.net application, i am using FormsAuthentication.SignOut(); method for sign out the application, but i have one strange requirement that i have to implement the FormsAuthentication.SignOut() by using Javascript function. Is it possible? if yes, please help me by providing the sample code to achieving this requirement.

Thanks in advance

like image 334
MAC Avatar asked Mar 25 '26 07:03

MAC


1 Answers

You can use AJAX to "load" the page that calls FormsAuthentication.SignOut.

Using JQuery it would look something like this, given that the logout button has ID "logout".

$('#logout').click(function () {
    $.ajax({
        url: '/logout',
        success: function () {
            document.location = '/logged_out';
        }, error: function () { 
            alert('Logout failed');
        }
    });
    return false;
});
like image 149
Deniz Dogan Avatar answered Mar 27 '26 20:03

Deniz Dogan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!