Monthly Archives: October 2007

Forcing Logout in Forms Authentication

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.

Directory synchronization batch file

Batch IconToday I ran into a problem that required two directories to be synchronized. This is more than just copying all of the files from one directory to another, which XCOPY does very well. I had to ensure that there were no orphaned files in the destination that were not already in the source. The closest thing XCOPY comes to this is to copy only files that already exist in the destination. This can be a problem when deploying ASP.NET projects over and over, because “XCOPY deployment” does not account for deleted or renamed files.

There are many shareware GUI programs that can synchronize two directories like I wanted, but that seemed like overkill. I basically wanted a Windows version of rsync that would work out of the box (if you know of one, please share in the comments). I had already fired up the old source control editor and was about to code up a quick console program to do this when I realized that the same thing could be accomplished with a recursive batch file. Ten minutes later, I had this little script: Read more »