How to get the current Windows user with ASP.NET Core RC2 MVC6 and IIS7
<p>I have an intranet site built in MVC6 using ASP.NET Core RC2.  I want to get the Windows username of the person accessing the intranet site.</p>

<p>So if Jim goes to the intranet site I want the site to receive "Domain\Jim", while if Anne goes to the intranet site I want the site to receive "Domain\Anne".</p>

<p>Only Windows Authentication is enabled on my IIS server, Anonymous Authentication is disabled.</p>

<p>My site is set to use Windows authentication and to disable anonymous authentication.</p>

<pre><code>&lt;system.web&gt;
    &lt;authentication mode="Windows" /&gt;
    &lt;authorization&gt;
        &lt;deny users="?"/&gt;
    &lt;/authorization&gt;
&lt;/system.web&gt;
</code></pre>

<p>Through Debug I can use <code>System.Security.Principal.WindowsIdentity.GetCurrent().Name</code>, but that of course returns "IIS APPPOOL\SiteName" on the IIS server.</p>

<p>I found many examples from older version of ASP.NET using HttpContext, and I tried injecting that into my controller with the following but userName ends up null.</p>

<pre><code>//Startup.cs
services.AddSingleton&lt;IHttpContextAccessor, HttpContextAccessor&gt;();

//HomeController.cs
public HomeController(IHttpContextAccessor _accessor)
{
    string userName = _accessor.HttpContext.User.Identity.Name;
}
</code></pre>

<p>What is the correct way to pass the Windows username to an intranet site in ASP.NET Core RC2 MVC6?</p>