19 October 2007
Forcing Logout in Forms Authentication
Posted by Barnabas under: How To .
Here’s a simple fix to a common ASP.NET development problem. The only code you really need to put on a log out page is “FormsAuthentication.SignOut()”. However, any controls or code that change based on authentication (such as the LoginView control or the LoginStatus control) will not reflect that the user is logged out until the following web page. This is bad for usability because you may be presenting links that are technically un-clickable. I’ve seen forum posts that advocate redirecting to another page, but there’s a simpler fix:
Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init FormsAuthentication.SignOut() Context.User = Nothing End Sub
Setting the Context.User to nothing does the trick.