title: How do I get the current Windows logged-in user's username?
body: <p>I am developing an intranet application using ASP.NET MVC 4. I am using custom forms authentication. When the user accesses the application I want to take the user's Windows logged-in username and check that username in my database. But I don't know how to take that username. I try to take it using the following code:</p>
  
  <pre><code>string CurLoggedInUsername = Environment.UserName;
  </code></pre>
  
  <p>This gives me the username when I run from Visual Studio, but when I host my application on IIS it gives a weird value. I also tried to use</p>
  
  <pre><code>string CurLoggedInUsername = httpcontext.current.user.identity.name;
  </code></pre>
  
  <p>but no use. Is there a way to get the user's Windows logged-in username before authentication?</p>