I'm using forms authentication in my web application. Is there any way to logout (FormsAuthentication.SignOut;) using jQuery library or javascript?
3 Answers
You could request that with XHR, except you will need to update your page to reflect the new state.
1 Comment
Zoidberg
By far the best answer here. Thank you for explaining it so elegantly.
Yes, you will need to create a controller action, if you're using MVC or a generic handler if you're using WebForms. This handler/action will need to call the FormsAuthentication.SignOut method. In jQuery you will need to make an ajax call to this action/handler.
$.post('/url/of/signout/action', null, function(data) {
//handle successful logout
});
Comments
Yes. You have to send an ajax request to the server. Look at ajax in the jquery documentation. http://api.jquery.com/jQuery.ajax/