Here is the situation:
- User logs in via username/password stored in an MSSQL database
- If the user is authenticated, the system makes a session variable with username/SHA1’d password and boolean if the user is logged in or not (for subsequent pages)
- I need to be able to destroy the session variable. I want a confirmation box as well.
This is what I have so far:
<script type='text/javascript'> //<![CDATA[ function doLogout() { try { var conf = false; conf = confirm('Really log out?'); if (conf === true) { $.post('logout.aspx'); } } catch (ex) { alert(ex); } } //]]> </script>
Since it is an ajax request won’t reload the page (the functionality works fine, the request destroys the session), I think I need a different approach to do this. I would really like to be able to do it all in ASP.NET if possible.
Any solution is welcome, as long as #3 above is fulfilled.
Well, for starters your solution depends on the user having Javascript, if they don’t they won’t be able to logout. I don’t think you should be using AJAX for this, just a simple link/button to logout.aspx would be fine, that could then correctly redirect them to the homepage with the ‘logged-out’ state set. You could then use some unobtrusive Javascript to add the confirmation.
jQuery version (since you mentioned that):
pure-Javascript version: