title: ASP.Net Core 6 WebApp: No default auth scheme with windows authentication
body: <p>i migrated my asp.net core mvc webapp from 5 to 6 and after that, windows auth was no more.
  This problem only occurs when i try to debug my webapp in VS22. When i deploy it to IIS, win auth is working flawlessly. i have tried many suggested solutions to this problems, such as adding</p>
  <pre><code>services.AddAuthentication(options =&gt; {
                  options.DefaultAuthenticateScheme = IISDefaults.AuthenticationScheme;
                  options.DefaultChallengeScheme = IISDefaults.AuthenticationScheme;
              }).AddNegotiate();
  </code></pre>
  <p>or</p>
  <pre><code>services.AddAuthentication(IISDefaults.AuthenticationScheme).AddNegotiate();
  </code></pre>
  <p>or</p>
  <pre><code>services.AddAuthorization(options =&gt;
              {
                  options.FallbackPolicy = options.DefaultPolicy;
              });
  </code></pre>
  <p>in various positions and orders in my Starup.cs.
  I have also tried different hosting implementations (Kestrel, IIS).
  I have also tried HttpSys where <strong>it worked</strong> but since i cant use it (company env requests IIS) i have to pass it unfortunately.
  No matter which browser i use (FF, Chrome, IE, Edge) i always get the same 500 internal error response with this exception in the web app:</p>
  <pre><code>Exception thrown: 
  'System.InvalidOperationException' in System.Private.CoreLib.dll 
  (&quot;No authenticationScheme was specified, and there was no DefaultChallengeScheme found. 
  The default schemes can be set using either AddAuthentication(string defaultScheme)
  or AddAuthentication(Action&lt;AuthenticationOptions&gt; configureOptions).&quot;)
  </code></pre>
  <p>Startup.cs:</p>
  <pre><code>public class Startup {
      private Config cfg;
      public Startup(IConfiguration configuration) {
          Configuration = configuration;
          this.cfg = new Config();
          Configuration.GetSection(&quot;appinfo&quot;).Bind(this.cfg);
          var client = new LoggingClient(cfg.GetAddressOf(&quot;Services.Api.Logging&quot;), cfg.DisplayName.Split('.').Last());
          client.WriteLogAsync(&quot;UI starting&quot;, LogSeverity.Info);
          ReferenceHelper.TestReferences(cfg);
      }
  
      public 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.AddControllersWithViews().AddRazorRuntimeCompilation();
          services.AddLocalization(options =&gt; options.ResourcesPath = &quot;Resources&quot;);
          services.AddMvc(options =&gt; {
              options.EnableEndpointRouting = false;
  
          }).AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix).AddDataAnnotationsLocalization();
  
          services.AddOptions();
          services.Configure&lt;Config&gt;(options =&gt; Configuration.GetSection(&quot;appinfo&quot;).Bind(options));
          services.AddSingleton&lt;IConfiguration&gt;(provider =&gt; Configuration);
          services.AddDistributedMemoryCache();
          services.AddSession(
              options =&gt; {
                  options.Cookie.IsEssential = true;
                  options.Cookie.SecurePolicy = Microsoft.AspNetCore.Http.CookieSecurePolicy.Always;
                  options.Cookie.SameSite = SameSiteMode.Strict;
                  options.Cookie.HttpOnly = true;
              });
          //services.AddAuthentication(HttpSysDefaults.AuthenticationScheme);
          //services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
          services.AddAuthentication(IISDefaults.AuthenticationScheme).AddNegotiate();
          services.AddScoped&lt;IClaimsTransformation, ClaimsTransformer&gt;();
          services.AddAuthorization();
          services.AddDataProtection()
              .SetApplicationName(&quot;InfoServices.Web.Administration&quot;)
              .PersistKeysToFileSystem(new System.IO.DirectoryInfo(DefaultPaths.WEB_KEYSTORE))
              .SetDefaultKeyLifetime(TimeSpan.FromDays(90));
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
          app.UseMiddleware&lt;ErrorLoggingMiddleware&gt;(new LoggingClient(cfg.GetAddressOf(&quot;InfoServices.Api.Logging&quot;), cfg.DisplayName.Split('.').Last()));
          app.UseForwardedHeaders();
  
          var supportedCultures = new[] { &quot;en&quot;, &quot;de&quot; };
          var localizationOptions = new RequestLocalizationOptions().SetDefaultCulture(supportedCultures[1])
              .AddSupportedCultures(supportedCultures)
              .AddSupportedUICultures(supportedCultures);
          localizationOptions.ApplyCurrentCultureToResponseHeaders = true;
  
  
          //if (env.IsDevelopment()) {
          //    //app.UseDeveloperExceptionPage();
          //    app.UseForwardedHeaders();
          //} else {
          //    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
          //}
          app.UseHsts();
          //app.UseAuthMiddleware();
          app.UseHttpsRedirection();
          app.UseStaticFiles();
          app.UseDefaultFiles();
          app.UseRouting();
          app.UseRequestLocalization(localizationOptions);
          app.UseAuthentication();
          app.UseAuthorization();
          app.UseSession();
  
  
          app.UseEndpoints(endpoints =&gt; {
              endpoints.MapControllers();
              endpoints.MapControllerRoute(
                  name: &quot;default&quot;,
                  pattern: &quot;{controller=Home}/{action=Overview}/{id?}&quot;);
          });
      }
  }
  </code></pre>
  <p>Program.cs:</p>
  <pre><code>public class Program{
      private static Config cfg;
      public static void Main(string[] args)
      {
          cfg = ConfigJsonHelper.GetConfig();
          CreateHostBuilder(args).Build().Run();
      }
  
  
      public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
          Host.CreateDefaultBuilder(args)
              .ConfigureWebHostDefaults(webBuilder =&gt;
              {
                  //webBuilder.UseHttpSys(options =&gt;
                  //{
                  //    options.Authentication.Schemes = Microsoft.AspNetCore.Server.HttpSys.AuthenticationSchemes.NTLM;
                  //    options.Authentication.AllowAnonymous = true;
                  //    options.UrlPrefixes.Add(&quot;https://&quot; + LocalDataHelper.GetCurrentHostname() + &quot;.domain.at:&quot; + cfg.Port);
                  //}).ConfigureAppConfiguration((hostingContext, config) =&gt;
                  //{
                  //    var env = hostingContext.HostingEnvironment;
                  //    //config.Sources.Clear();
                  //    config.SetBasePath(env.ContentRootPath);
                  //    config.AddJsonFile(&quot;appinfo.json&quot;, optional: false, reloadOnChange: true);
                  //    config.AddEnvironmentVariables();
                  //});
                  //webBuilder.UseKestrel().ConfigureAppConfiguration((hostingContext, config) =&gt;
                  //{
                  //    var env = hostingContext.HostingEnvironment;
                  //    //config.Sources.Clear();
                  //    config.SetBasePath(env.ContentRootPath);
                  //    config.AddJsonFile(&quot;appinfo.json&quot;, optional: false, reloadOnChange: true);
                  //    config.AddEnvironmentVariables();
  
                  //}).UseUrls(&quot;https://&quot; + LocalDataHelper.GetCurrentHostname() + &quot;.domain.at:&quot; + cfg.Port);
                  webBuilder.UseIISIntegration().ConfigureAppConfiguration((hostingContext, config) =&gt;
                  {
                      var env = hostingContext.HostingEnvironment;
                      //config.Sources.Clear();
                      config.SetBasePath(env.ContentRootPath);
                      config.AddJsonFile(&quot;appinfo.json&quot;, optional: false, reloadOnChange: true);
                      config.AddEnvironmentVariables();
  
                  }).UseUrls(&quot;https://&quot; + LocalDataHelper.GetCurrentHostname() + &quot;.domain.at:&quot; + cfg.Port);
                  webBuilder.UseStartup&lt;Startup&gt;();
              });
  }
  </code></pre>
  <p>For nuget pkgs i have:</p>
  <pre><code>&quot;Microsoft.AspNetCore.Authentication.Negotiate&quot; Version=&quot;6.0.2&quot; 
  &quot;jQuery&quot; Version=&quot;3.6.0&quot; 
  &quot;jquery.TypeScript.DefinitelyTyped&quot; Version=&quot;3.1.2&quot; 
  &quot;jQuery.Validation&quot; Version=&quot;1.19.3&quot; 
  &quot;Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation&quot; Version=&quot;6.0.2&quot; 
  &quot;Microsoft.AspNetCore.StaticFiles&quot; Version=&quot;2.2.0&quot; 
  &quot;Microsoft.Extensions.Configuration.Binder&quot; Version=&quot;6.0.0&quot; 
  &quot;Microsoft.IdentityModel&quot; Version=&quot;7.0.0&quot; 
  &quot;Microsoft.jQuery.Unobtrusive.Validation&quot; Version=&quot;3.2.12&quot; 
  &quot;Newtonsoft.Json&quot; Version=&quot;13.0.1&quot; 
  &quot;Microsoft.TypeScript.MSBuild&quot; Version=&quot;4.5.3&quot;
  </code></pre>
  <p>launchSettings.json:</p>
  <pre><code>{
    &quot;iisSettings&quot;: {
      &quot;windowsAuthentication&quot;: true,
      &quot;anonymousAuthentication&quot;: false,
      &quot;iisExpress&quot;: {
        &quot;applicationUrl&quot;: &quot;http://localhost:60248&quot;,
        &quot;sslPort&quot;: 6900,
        &quot;windowsAuthentication&quot;: true,
        &quot;anonymousAuthentication&quot;: false
      }
    },
      &quot;profiles&quot;: {
  
          &quot;Development&quot;: {
              &quot;commandName&quot;: &quot;Project&quot;,
              &quot;environmentVariables&quot;: {
                  &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Development&quot;
              }
          }
      }
  }
  </code></pre>