|
1 | 1 | using System;
|
2 | 2 | using System.IO;
|
| 3 | +using System.Threading.Tasks; |
3 | 4 | using Microsoft.AspNetCore.Hosting;
|
4 | 5 | using Microsoft.AspNetCore.Server.HttpSys;
|
5 | 6 | using Microsoft.Extensions.Configuration;
|
| 7 | +using Microsoft.Extensions.Hosting; |
6 | 8 | using Microsoft.Extensions.Logging;
|
7 | 9 |
|
8 | 10 | namespace MusicStore
|
9 | 11 | {
|
10 | 12 | public static class Program
|
11 | 13 | {
|
12 |
| - public static void Main(string[] args) |
| 14 | + public static Task Main(string[] args) |
13 | 15 | {
|
14 | 16 | var config = new ConfigurationBuilder()
|
15 | 17 | .AddCommandLine(args)
|
16 | 18 | .AddEnvironmentVariables(prefix: "ASPNETCORE_")
|
17 | 19 | .Build();
|
18 | 20 |
|
19 |
| - var builder = new WebHostBuilder() |
20 |
| - .UseConfiguration(config) |
21 |
| - .UseIISIntegration() |
22 |
| - .UseStartup("MusicStore") |
23 |
| - .UseDefaultServiceProvider((context, options) => { |
24 |
| - options.ValidateScopes = true; |
25 |
| - }); |
| 21 | + var builder = new HostBuilder() |
| 22 | + .ConfigureWebHost(webHostBuilder => |
| 23 | + { |
| 24 | + webHostBuilder |
| 25 | + .UseConfiguration(config) |
| 26 | + .UseIISIntegration() |
| 27 | + .UseStartup("MusicStore"); |
26 | 28 |
|
27 |
| - var environment = builder.GetSetting("environment") ?? |
| 29 | + var environment = webHostBuilder.GetSetting("environment") ?? |
28 | 30 | Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
|
29 | 31 |
|
30 |
| - if (string.Equals(builder.GetSetting("server"), "Microsoft.AspNetCore.Server.HttpSys", System.StringComparison.Ordinal)) |
31 |
| - { |
32 |
| - if (string.Equals(environment, "NtlmAuthentication", System.StringComparison.Ordinal)) |
33 |
| - { |
34 |
| - // Set up NTLM authentication for WebListener like below. |
35 |
| - // For IIS and IISExpress: Use inetmgr to setup NTLM authentication on the application vDir or |
36 |
| - // modify the applicationHost.config to enable NTLM. |
37 |
| - builder.UseHttpSys(options => |
| 32 | + if (string.Equals(webHostBuilder.GetSetting("server"), "Microsoft.AspNetCore.Server.HttpSys", System.StringComparison.Ordinal)) |
38 | 33 | {
|
39 |
| - options.Authentication.Schemes = AuthenticationSchemes.NTLM; |
40 |
| - options.Authentication.AllowAnonymous = false; |
41 |
| - }); |
42 |
| - } |
43 |
| - else |
44 |
| - { |
45 |
| - builder.UseHttpSys(); |
46 |
| - } |
47 |
| - } |
48 |
| - else |
49 |
| - { |
50 |
| - builder.UseKestrel(); |
51 |
| - } |
| 34 | + if (string.Equals(environment, "NtlmAuthentication", System.StringComparison.Ordinal)) |
| 35 | + { |
| 36 | + // Set up NTLM authentication for WebListener like below. |
| 37 | + // For IIS and IISExpress: Use inetmgr to setup NTLM authentication on the application vDir or |
| 38 | + // modify the applicationHost.config to enable NTLM. |
| 39 | + webHostBuilder.UseHttpSys(options => |
| 40 | + { |
| 41 | + options.Authentication.Schemes = AuthenticationSchemes.NTLM; |
| 42 | + options.Authentication.AllowAnonymous = false; |
| 43 | + }); |
| 44 | + } |
| 45 | + else |
| 46 | + { |
| 47 | + webHostBuilder.UseHttpSys(); |
| 48 | + } |
| 49 | + } |
| 50 | + else |
| 51 | + { |
| 52 | + webHostBuilder.UseKestrel(); |
| 53 | + } |
52 | 54 |
|
53 |
| - // In Proc |
54 |
| - builder.UseIIS(); |
| 55 | + // In Proc |
| 56 | + webHostBuilder.UseIIS(); |
55 | 57 |
|
56 |
| - builder.ConfigureLogging(factory => |
57 |
| - { |
58 |
| - factory.AddConsole(); |
| 58 | + webHostBuilder.ConfigureLogging(factory => |
| 59 | + { |
| 60 | + factory.AddConsole(); |
59 | 61 |
|
60 |
| - var logLevel = string.Equals(environment, "Development", StringComparison.Ordinal) ? LogLevel.Information : LogLevel.Warning; |
61 |
| - factory.SetMinimumLevel(logLevel); |
| 62 | + var logLevel = string.Equals(environment, "Development", StringComparison.Ordinal) ? LogLevel.Information : LogLevel.Warning; |
| 63 | + factory.SetMinimumLevel(logLevel); |
62 | 64 |
|
63 |
| - // Turn off Info logging for EF commands |
64 |
| - factory.AddFilter("Microsoft.EntityFrameworkCore.Database.Command", LogLevel.Warning); |
65 |
| - }); |
| 65 | + // Turn off Info logging for EF commands |
| 66 | + factory.AddFilter("Microsoft.EntityFrameworkCore.Database.Command", LogLevel.Warning); |
| 67 | + }); |
| 68 | + }) |
| 69 | + .UseDefaultServiceProvider((context, options) => { |
| 70 | + options.ValidateScopes = true; |
| 71 | + }); |
66 | 72 |
|
67 | 73 | var host = builder.Build();
|
68 | 74 |
|
69 |
| - host.Run(); |
| 75 | + return host.RunAsync(); |
70 | 76 | }
|
71 | 77 | }
|
72 | 78 | }
|
0 commit comments