title: Identity Impersonation with ASP.NET 4 MVC not working as expected
body: <p>I am in the process of building a Intranet MVC 4 application for our analysts. The goal is to allow internal users access to this application without having to sign on given they are part of our internal network. When they access the application I want to be able to capture their windows user name and check against the active directory using LDAP and retrieve the department they belong to and display the relevant details on the screen. Based on the advice from different fora, I have chosen Windows Authentication for this application and I was able to test the app successfully running from Visual Studio. The trouble I am having is when I deploy this to our UAT server running IIS 7.5.</p>
  
  <pre><code>&lt;authentication mode="Windows"&gt;
  &lt;/authentication&gt;
  &lt;identity impersonate="false" /&gt;
  </code></pre>
  
  <p>This is the current state of my Web.config file. Irrespective of whether impersonate is true or false, the application seems to not capture the windows username of the browser from which the application is accessed. Is </p>
  
  <blockquote>
    <p>impersonate = true</p>
  </blockquote>
  
  <p>required for this at all? In the Welcome message on the homepage, I always see the windows user name of the computer where the application is hosted/IIS is running. I have tried a wide variety of ways to capture the Windows User name of the incoming user request.</p>
  
  <pre><code>string name = System.Web.HttpContext.Current.User.Identity.Name;
  string name = System.Web.HttpContext.Current.Request.LogonUserIdentity.Name;
  string name = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
  string name = System.Web.HttpContext.Current.Request.ServerVariables["LOGON_USER"].Name;
  </code></pre>
  
  <p>etc. I also looked into several other posts here like <a href="https://stackoverflow.com/questions/1267071/how-to-get-windows-user-name-when-identity-impersonate-true-in-asp-net">this</a>. But I am unable to get it to work. I am afraid that I am trying to achieve this by accident rather than really understanding what is going on? Could someone please guide me in the right direction?</p>