44#pragma warning disable CS0618 // Type or member is obsolete
55
66using System ;
7- using Microsoft . AspNetCore ;
87using Microsoft . AspNetCore . Builder ;
98using Microsoft . AspNetCore . HostFiltering ;
109using Microsoft . AspNetCore . Hosting ;
@@ -21,31 +20,35 @@ static void Main(string[] args)
2120 {
2221 string responseMessage = null ;
2322
24- WebHost . CreateDefaultBuilder ( new [ ] { "--cliKey" , "cliValue" } )
25- . ConfigureServices ( ( context , service ) => responseMessage = responseMessage ?? GetResponseMessage ( context ) )
26- . ConfigureKestrel ( options => options
27- . Configure ( options . ConfigurationLoader . Configuration )
28- . Endpoint ( "HTTP" , endpointOptions =>
29- {
30- if ( responseMessage == null
31- && ! string . Equals ( "KestrelEndPointSettingValue" , endpointOptions . ConfigSection [ "KestrelEndPointSettingName" ] ) )
32- {
33- responseMessage = "Default Kestrel configuration not read." ;
34- }
35- } ) )
36- . Configure ( app => app . Run ( context =>
23+ Host . CreateDefaultBuilder ( new [ ] { "--cliKey" , "cliValue" } )
24+ . ConfigureWebHostDefaults ( webBuilder =>
3725 {
38- // Verify allowed hosts were loaded
39- var hostFilteringOptions = app . ApplicationServices . GetRequiredService < IOptions < HostFilteringOptions > > ( ) ;
40- var hosts = string . Join ( ',' , hostFilteringOptions . Value . AllowedHosts ) ;
41- if ( responseMessage == null && ! string . Equals ( "example.com,127.0.0.1" , hosts , StringComparison . Ordinal ) )
42- {
43- responseMessage = "AllowedHosts not loaded into Options." ;
44- }
26+ webBuilder
27+ . ConfigureServices ( ( context , service ) => responseMessage = responseMessage ?? GetResponseMessage ( context ) )
28+ . ConfigureKestrel ( options => options
29+ . Configure ( options . ConfigurationLoader . Configuration )
30+ . Endpoint ( "HTTP" , endpointOptions =>
31+ {
32+ if ( responseMessage == null
33+ && ! string . Equals ( "KestrelEndPointSettingValue" , endpointOptions . ConfigSection [ "KestrelEndPointSettingName" ] ) )
34+ {
35+ responseMessage = "Default Kestrel configuration not read." ;
36+ }
37+ } ) )
38+ . Configure ( app => app . Run ( context =>
39+ {
40+ // Verify allowed hosts were loaded
41+ var hostFilteringOptions = app . ApplicationServices . GetRequiredService < IOptions < HostFilteringOptions > > ( ) ;
42+ var hosts = string . Join ( ',' , hostFilteringOptions . Value . AllowedHosts ) ;
43+ if ( responseMessage == null && ! string . Equals ( "example.com,127.0.0.1" , hosts , StringComparison . Ordinal ) )
44+ {
45+ responseMessage = "AllowedHosts not loaded into Options." ;
46+ }
4547
46- var hostingEnvironment = app . ApplicationServices . GetRequiredService < IHostEnvironment > ( ) ;
47- return context . Response . WriteAsync ( responseMessage ?? hostingEnvironment . ApplicationName ) ;
48- } ) )
48+ var hostingEnvironment = app . ApplicationServices . GetRequiredService < IHostEnvironment > ( ) ;
49+ return context . Response . WriteAsync ( responseMessage ?? hostingEnvironment . ApplicationName ) ;
50+ } ) ) ;
51+ } )
4952 . Build ( )
5053 . Run ( ) ;
5154 }
0 commit comments