diff --git a/src/MusicStore/Program.cs b/src/MusicStore/Program.cs index 3aa4520..cc49ac2 100644 --- a/src/MusicStore/Program.cs +++ b/src/MusicStore/Program.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Hosting; +using Microsoft.Net.Http.Server; namespace MusicStore { @@ -6,14 +7,27 @@ namespace MusicStore { public static void Main(string[] args) { - var host = new WebHostBuilder() + var builder = new WebHostBuilder() // We set the server by name before default args so that command line arguments can override it. // This is used to allow deployers to choose the server for testing. .UseServer("Microsoft.AspNetCore.Server.Kestrel") .UseDefaultHostingConfiguration(args) .UseIISIntegration() - .UseStartup("MusicStore") - .Build(); + .UseStartup("MusicStore"); + + if (string.Equals(builder.GetSetting("server"), "Microsoft.AspNetCore.Server.WebListener", System.StringComparison.Ordinal) + && string.Equals(builder.GetSetting("environment"), "NtlmAuthentication", System.StringComparison.Ordinal)) + { + // Set up NTLM authentication for WebListener like below. + // For IIS and IISExpress: Use inetmgr to setup NTLM authentication on the application vDir or + // modify the applicationHost.config to enable NTLM. + builder.UseWebListener(options => + { + options.Listener.AuthenticationManager.AuthenticationSchemes = AuthenticationSchemes.NTLM; + }); + } + + var host = builder.Build(); host.Run(); } diff --git a/src/MusicStore/StartupNtlmAuthentication.cs b/src/MusicStore/StartupNtlmAuthentication.cs index 6a4f0c7..da5dca8 100644 --- a/src/MusicStore/StartupNtlmAuthentication.cs +++ b/src/MusicStore/StartupNtlmAuthentication.cs @@ -102,16 +102,6 @@ namespace MusicStore // request pipeline. // Note: Not recommended for production. app.UseDeveloperExceptionPage(); - - // Set up NTLM authentication for WebListener like below. - // For IIS and IISExpress: Use inetmgr to setup NTLM authentication on the application vDir or - // modify the applicationHost.config to enable NTLM. - var listener = app.ServerFeatures.Get(); - if (listener != null) - { - listener.AuthenticationManager.AuthenticationSchemes = AuthenticationSchemes.NTLM; - } - app.UseDatabaseErrorPage(); // Add the runtime information page that can be used by developers