title: Asp.Net Core 2.1 Windows Auth. HttpContext.User.Identity.Name not working in IIS
body: <p>Environment:</p>
  
  <p>Windows 10
  IIS 10 / Visual Studio 2017 Community w/ IIS Express
  Windows Authentication security feature installed
  Windows Authentication Enabled &amp; Basic Authentication Enabled &amp; Anonymous Authentication Disabled</p>
  
  <p>I have a Asp.Net Core 2.1 Project and this project will work in intranet. So i need to windows authentication.</p>
  
  <p>STARTUP:</p>
  
  <pre><code> public class Startup
      {
          private IConfigurationRoot _appSettings;
          public Startup(IHostingEnvironment env, IConfiguration configuration)
          {
              Configuration = configuration;
              _appSettings = new ConfigurationBuilder()
               .SetBasePath(env.ContentRootPath)
               .AddJsonFile("appsettings.json")
               .Build();
  
          }
  
          private IConfiguration Configuration { get; }
  
          // This method gets called by the runtime. Use this method to add services to the container.
          public void ConfigureServices(IServiceCollection services)
          {
  
  
              services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
              services.TryAddSingleton&lt;IHttpContextAccessor, HttpContextAccessor&gt;();
  
              services.AddSession(options =&gt; {
                  options.IdleTimeout = TimeSpan.FromMinutes(8640); //Sessions Time
              });
              services.AddDistributedMemoryCache();
  
              services.AddDbContext&lt;PMContext&gt;();
              services.AddSingleton&lt;IConfigurationRoot&gt;(_appSettings);
              PMContext.ConnectionString = _appSettings.GetConnectionString("DefaultConnection");
              services.AddAuthentication(IISDefaults.AuthenticationScheme);
  
          }
  
          public void Configure(IApplicationBuilder app, IHostingEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
              else
              {
                  app.UseExceptionHandler("/Home/Error");
                  app.UseHsts();
              }
              app.UseHangfireServer();
              app.UseHttpsRedirection();
              app.UseSession();
              app.UseStaticFiles();
              app.UseStatusCodePages();
              app.UseAuthentication();
              app.UseCookiePolicy();
              app.UseMvc(routes =&gt;
              {
                  routes.MapRoute(
                      name: "default",
                      template: "{controller=Intro}/{action=Index}/{id?}");
              });
  
          }
      }
  public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  {
      if (env.IsDevelopment())
      {
          app.UseDeveloperExceptionPage();
      }
  
      app.UseAuthentication();
      app.Run(async (context) =&gt;
      {
          await context.Response.WriteAsync(JsonConvert.SerializeObject(new
          {                
              UserName = context?.User?.Identity?.Name
          }));
      });     
  </code></pre>
  
  <p>//In my home controller;</p>
  
  <p><strong>var UserComputerName = contextAccessor.HttpContext.User.Identity.Name;</strong></p>
  
  <p>This code working my localhost but don't working in IIS Server :/ I tried same error solves but I couldn't solve it.</p>