title: How to get current Windows user name in ASP.NET Core 2.2, when web application runs as Administrator?
body: <p>We have an ASP.NET Core 2.2 web-application, hosted on IIS and run under <strong>MyComputer\MyAdminUser</strong> Windows user (with administrator permissions). I need to get the name of current Windows user, which are working with our application, f.ex. <strong>MyComputer\MyClientUser</strong>. All client users are local users (<strong>MyComputer\ ...</strong>). How can I do it?</p>
  
  <p>I've tried to use different approaches, but noone brings me expected result (<strong>MyClientUser</strong>):</p>
  
  <pre><code>1. HttpContext.Current.Request.LogonUserIdentity;
  </code></pre>
  
  <p>'HttpContext' does not contain a definition for '<code>Current</code>' and no accessible extension method 'Current' accepting a first argument of type 'HttpContext' could be found...</p>
  
  <pre><code>2. Request.LogonUserIdentity;
  </code></pre>
  
  <p>the same problem with <code>LogonUserIdentity</code></p>
  
  <pre><code>3. Request.ServerVariables["LOGON_USER"];
  </code></pre>
  
  <p>the same problem with <code>ServerVariables</code></p>
  
  <pre><code>4. Request.Headers
  </code></pre>
  
  <p>This list doesn't include any information about current Windows user</p>
  
  <pre><code>5. Environment.UserName
  </code></pre>
  
  <p>The result is <strong>"MyAdminUser"</strong></p>
  
  <pre><code>6. WindowsIdentity.GetCurrent().Name
  </code></pre>
  
  <p>The result is <strong>"MyComputer\MyAdminUser"</strong></p>
  
  <pre><code>7. ManagementObjectCollection collection = 
        new ManagementObjectSearcher("SELECT UserName FROM Win32_ComputerSystem")
        .Get();
     collection?.Cast&lt;ManagementBaseObject&gt;()?.First()?.Properties?["UserName"]?.Value
  </code></pre>
  
  <p>For Visual Studio result is correct (current Windows user), but on IIS the <code>Properties?["UserName"]?.Value</code> is null or empty (<code>Properties?["UserName"]?.Name</code> = <code>"UserName"</code>)</p>
  
  <p>What am I doing wrong and how can I get expected name?</p>