title: Windows and Anonymous Authentication in .Net Core 2.0
body: <p>I'm trying to mix <strong>Windows</strong> and <strong>Anonymous</strong> authentication in a <strong>.Net Core 2.0</strong> empty web app. I would like to <strong>avoid the [Authorize]</strong> attribute as I do not want to use Mvc or controllers.</p>
  
  <p>My setup is as follows:</p>
  
  <ol>
  <li><p>I created an empty .Net Core 2.0 web application</p></li>
  <li><p>I went to project properties -> Debug -> Checked "Enable Windows Authentication" and disabled "Enable Anonymous Authentication".
  Now "windowsAuthentication": true and "anonymousAuthentication": false appeared in my launchSettings.json under "IIS".</p></li>
  <li><p>Inside Startup.cs, in ConfigureServices I added
  <code>services.AddAuthentication(Microsoft.AspNetCore.Server.IISIntegration.IISDefaults.AuthenticationScheme);</code> as mentioned in <a href="https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x#windows-authentication-httpsys--iisintegration" rel="noreferrer">https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x#windows-authentication-httpsys--iisintegration</a></p></li>
  <li><p>I added a simple <code>Console.WriteLine(context.User.Identity.Name);</code> to see that it works inside app.Run and...
  It all works!</p></li>
  </ol>
  
  <p>However... as soon as I set "anonymousAuthentication" to true in launchSettings.json it stops working and I cannot figure out what can I do to make the Windows authentication work alongside with it. <code>Context.User.Identity.IsAuthenticated</code> is always false.
  As you can see my configuration is very simple and I need it to stay this way. I want to enable/disable windows authentication on certain dynamic routes, so using controllers with the [Authorize] attribute is not an option.</p>
  
  <p>What I'm trying to achieve is a simple app where the url "/authenticated" would reply with the value of <code>context.User.Identity.Name</code> and the url "/public" would reply with something like say "This is a public page!".
  Something similar to <a href="https://stackoverflow.com/questions/42581132/ntlm-authentication-on-specific-route-in-asp-net-core">NTLM authentication on specific route in ASP.NET Core</a> but without the [Authorize] attribute and controllers.
  The resources are very scarce... Anyone have any idea what I could be missing?
  Thanks!</p>