title: How to get current windows username and disable the credentials prompting?
body: <p>I have a C#.NET 4.0 application running under IIS 7 on Windows Server 2008 with IIS7 server. The application will run in the company intranet that automatically grabs the logged-in Windows username of the person viewing the page without being prompted to enter credentials when the page loads. Now i'm facing 2 problems:</p>
  
  <p>1) Currently, the apps returns the production server name (eg: XYZ\sam) that the application located at. I want to get the current logged on username (eg: ABC\sam). It works fine at localhost but not at production server.</p>
  
  <p>I've enabled <code>&lt;authentication mode="Windows" /&gt;</code> at web.config , enabled windows authentication and disabled anonymous authentication at IIS.</p>
  
  <p>I've tried <code>Page.User.Identity.Name</code>, <code>System.Web.HttpContext.Current.User.Identity.Name</code>, <code>System.Security.Principal.WindowsIdentity.GetCurrent().Name</code>, and others but still failed to get the right name. How to get the current windows logged on user?</p>
  
  <p>2) When I want to access the application, it keeps prompting out a windows for username and password. If I ignore it, it will prompt out </p>
  
  <blockquote>
    <p>401 - Unauthorized: Access is denied due to invalid credentials. You
    do not have permission to view this directory or page using the
    credentials that you supplied.</p>
  </blockquote>
  
  <p>How i gona fix it?</p>