User.Identity.Name is empty / blank when using Windows authentication in ASP.NET MVC 3 Beta

If (like me) you have been tearing your hair out wondering why the User.Identity.Name property always returns an empty / blank string when using <authentication type=”Windows”> in the new ASP.NET MVC 3 Beta then the answer is surprisingly simple:

As detailed in the Known Issues section of the release notes, just add the following line to the <appSettings> section of the web.config:

<add key="autoFormsAuthentication" value="false" />

Also, make sure you have the <authentication> type set to “Windows” as above, and (optionally) if using the built-in Visual Studio web server (aka “Cassini”) you can also check the “NTLM Authentication” option in the Properties / Web tab.