ASP.NET MVC + AD + Windows Authentication: How to Logout
By Gonzalo. Filed in Asp.net MVC |In ASP.NET MVC applications using Windows Authentication against a domain, we have two possible ways to login:
1) If the user is on a PC added to the domain, login to the application is not needed becasue it is done automatically with the user’s credentials
2) If the user wants to use the application from a PC outside de domain, he must enter his username/password
In this second case, probably the user wants to logout after using the app. How can we do this ?
As we can’t clear our credentials using .Net code, we must “logout” using Javascript. Thus is, clear the authentication cache.
In the Header section we must add this code:
And in the body section we call this function:
<a href=”../../Default.aspx” onclick=”javascript:Logout();”>[ Salir ]</a>
Notes: this code works fine on IE 6 + SP1 or higher. Otherwise, the user must close all broser’s windows in order to logout.
Hope you find this usefull…..