title: How do you get Windows user domain/username with C# Razor on IIS 10?
body: <p>Trying to build a web app that will utilize single-sign-on using Windows authentication with Active Directory. I'm having trouble getting the logged in Windows user domain and username. Things I have tried:</p>
  
  <ul>
  <li><p><code>WindowsIdentity.GetCurrent().Name</code></p>
  
  <p>Returns <code>IIS APPPOOL\DefaultAppPool</code></p></li>
  <li><p><code>System.Environment.UserName</code></p>
  
  <p>Returns <code>DefaultAppPool</code></p></li>
  <li><p><code>Page.User.Identity.Name</code></p>
  
  <p>Results in a compilation error</p>
  
  <p><br>
  Anonymous Authentication is disabled
  <br>
  ASP.NET Impersonation is enabled
  <br>
  Windows Authentication is enabled</p>
  
  <p><br>
  Web.config</p>
  
  <blockquote>
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;appSettings&gt;
      &lt;add key="EnableSimpleMembership" value="false" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;compilation debug="false" targetFramework="4.6.1"&gt;
        &lt;assemblies&gt;
          &lt;add assembly="System.Net.Http, Version=4.1.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /&gt;
          &lt;add assembly="Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
        &lt;/assemblies&gt;
      &lt;/compilation&gt;
      &lt;httpRuntime targetFramework="4.6.1" /&gt;
      &lt;authentication mode="Windows" /&gt;
      &lt;authorization&gt;
        &lt;deny users="?" /&gt;
      &lt;/authorization&gt;
      &lt;identity impersonate="true" /&gt;
    &lt;/system.web&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Security.Cryptography.X509Certificates" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Microsoft.Win32.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
    &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"&gt;
      &lt;/modules&gt;
      &lt;validation validateIntegratedModeConfiguration="false" /&gt;
      &lt;handlers&gt;
        &lt;remove name="ExtensionlessUrlHandler-Integrated-4.0" /&gt;
        &lt;remove name="OPTIONSVerbHandler" /&gt;
        &lt;remove name="TRACEVerbHandler" /&gt;
        &lt;add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /&gt;
      &lt;/handlers&gt;
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>
  </blockquote></li>
  </ul>