title: ASP.NET Core 2.2 - Use HTTP.sys only in Development
body: <p>I have an application in ASP.NET Core 2.2 which requires Windows Authentication.
  To have a full development environment, we use HTTP.sys because it allows us to have full NTLM support with the watcher:</p>
  
  <pre><code>dotnet watch run
  </code></pre>
  
  <p>The problem occurrs, when we deploy into IIS 10.0</p>
  
  <p>Startup file is configured as following:</p>
  
  <pre><code>services.AddAuthentication(HttpSysDefaults.AuthenticationScheme);
  services.Configure&lt;IISOptions&gt;(options =&gt;
  {
      options.AutomaticAuthentication = true;
  });
  </code></pre>
  
  <p>Program is configured as following:</p>
  
  <pre><code>    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =&gt;
          WebHost
              .CreateDefaultBuilder(args)
              .UseIISIntegration()
              .UseHttpSys(options =&gt;
              {
                  options.Authentication.Schemes = AuthenticationSchemes.NTLM;
                  options.Authentication.AllowAnonymous = false;
              })
              .UseStartup&lt;Startup&gt;()
              .UseSerilog((hostingContext, loggerConfiguration) =&gt; loggerConfiguration
                  .ReadFrom.Configuration(hostingContext.Configuration)
                  .Enrich.FromLogContext()
                  .WriteTo.Console());
  }
  </code></pre>
  
  <p>On local development everything works as expected.
  When we deploy, we have the following errors:</p>
  
  <p>If we set the web.config <code>hostingModel="InProcess"</code></p>
  
  <pre><code>2019-10-16 17:03:14.320 +02:00 [Fatal] Application startup exception
  System.InvalidOperationException: Application is running inside IIS process but is not configured to use IIS server.
     at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.&lt;&gt;c__DisplayClass2_0.&lt;Configure&gt;b__0(IApplicationBuilder app)
     at Microsoft.AspNetCore.HostFilteringStartupFilter.&lt;&gt;c__DisplayClass0_0.&lt;Configure&gt;b__0(IApplicationBuilder app)
     at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.&lt;&gt;c__DisplayClass0_0.&lt;Configure&gt;b__0(IApplicationBuilder builder)
     at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
  </code></pre>
  
  <p>If we remove it, so Out Process:</p>
  
  <pre><code>2019-10-16 17:10:38.151 +02:00 [Fatal] Application startup exception
  System.InvalidOperationException: Scheme already exists: Windows
     at Microsoft.AspNetCore.Authentication.AuthenticationSchemeProvider.AddScheme(AuthenticationScheme scheme)
     at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware..ctor(RequestDelegate next, ILoggerFactory loggerFactory, IOptions`1 options, String pairingToken, Boolean isWebsocketsSupported, IAuthenticationSchemeProvider authentication, IApplicationLifetime applicationLifetime)
  --- End of stack trace from previous location where exception was thrown ---
     at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
     at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
     at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.&lt;&gt;c__DisplayClass4_0.&lt;UseMiddleware&gt;b__0(RequestDelegate next)
     at Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build()
     at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
  </code></pre>