Program.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) .NET Foundation. All rights reserved.
  2. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  3. using System;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.AspNetCore.Server.HttpSys;
  6. using Microsoft.Extensions.Configuration;
  7. using Microsoft.Extensions.Logging;
  8. namespace ServerComparison.TestSites
  9. {
  10. public static class Program
  11. {
  12. public static void Main(string[] args)
  13. {
  14. var config = new ConfigurationBuilder()
  15. .AddCommandLine(args)
  16. .Build();
  17. var builder = new WebHostBuilder()
  18. .UseConfiguration(config)
  19. .ConfigureLogging((_, factory) =>
  20. {
  21. factory.AddConsole();
  22. factory.AddFilter("Console", level => level >= LogLevel.Warning);
  23. })
  24. .UseStartup("ServerComparison.TestSites");
  25. // Switch between Kestrel, IIS, and HttpSys for different tests. Default to Kestrel for normal app execution.
  26. if (string.Equals(builder.GetSetting("server"), "Microsoft.AspNetCore.Server.HttpSys", StringComparison.Ordinal))
  27. {
  28. if (string.Equals(builder.GetSetting("environment") ??
  29. Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"),
  30. "NtlmAuthentication", System.StringComparison.Ordinal))
  31. {
  32. // Set up NTLM authentication for HttpSys as follows.
  33. // For IIS and IISExpress use inetmgr to setup NTLM authentication on the application or
  34. // modify the applicationHost.config to enable NTLM.
  35. builder.UseHttpSys(options =>
  36. {
  37. options.Authentication.AllowAnonymous = true;
  38. options.Authentication.Schemes =
  39. AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM;
  40. });
  41. }
  42. else
  43. {
  44. builder.UseHttpSys();
  45. }
  46. }
  47. else
  48. {
  49. // Check that we are not using IIS inproc before we add Kestrel.
  50. builder.UseKestrel();
  51. }
  52. builder.UseIISIntegration();
  53. builder.UseIIS();
  54. var host = builder.Build();
  55. host.Run();
  56. }
  57. }
  58. }