Skip to content

[MusicStore] Move to GenericHost #24284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 47 additions & 41 deletions src/MusicStore/samples/MusicStore/Program.cs
Original file line number Diff line number Diff line change
@@ -1,72 +1,78 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.HttpSys;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace MusicStore
{
public static class Program
{
public static void Main(string[] args)
public static Task Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddCommandLine(args)
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
.Build();

var builder = new WebHostBuilder()
.UseConfiguration(config)
.UseIISIntegration()
.UseStartup("MusicStore")
.UseDefaultServiceProvider((context, options) => {
options.ValidateScopes = true;
});
var builder = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseConfiguration(config)
.UseIISIntegration()
.UseStartup("MusicStore");

var environment = builder.GetSetting("environment") ??
var environment = webHostBuilder.GetSetting("environment") ??
Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

if (string.Equals(builder.GetSetting("server"), "Microsoft.AspNetCore.Server.HttpSys", System.StringComparison.Ordinal))
{
if (string.Equals(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.UseHttpSys(options =>
if (string.Equals(webHostBuilder.GetSetting("server"), "Microsoft.AspNetCore.Server.HttpSys", System.StringComparison.Ordinal))
{
options.Authentication.Schemes = AuthenticationSchemes.NTLM;
options.Authentication.AllowAnonymous = false;
});
}
else
{
builder.UseHttpSys();
}
}
else
{
builder.UseKestrel();
}
if (string.Equals(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.
webHostBuilder.UseHttpSys(options =>
{
options.Authentication.Schemes = AuthenticationSchemes.NTLM;
options.Authentication.AllowAnonymous = false;
});
}
else
{
webHostBuilder.UseHttpSys();
}
}
else
{
webHostBuilder.UseKestrel();
}

// In Proc
builder.UseIIS();
// In Proc
webHostBuilder.UseIIS();

builder.ConfigureLogging(factory =>
{
factory.AddConsole();
webHostBuilder.ConfigureLogging(factory =>
{
factory.AddConsole();

var logLevel = string.Equals(environment, "Development", StringComparison.Ordinal) ? LogLevel.Information : LogLevel.Warning;
factory.SetMinimumLevel(logLevel);
var logLevel = string.Equals(environment, "Development", StringComparison.Ordinal) ? LogLevel.Information : LogLevel.Warning;
factory.SetMinimumLevel(logLevel);

// Turn off Info logging for EF commands
factory.AddFilter("Microsoft.EntityFrameworkCore.Database.Command", LogLevel.Warning);
});
// Turn off Info logging for EF commands
factory.AddFilter("Microsoft.EntityFrameworkCore.Database.Command", LogLevel.Warning);
});
})
.UseDefaultServiceProvider((context, options) => {
options.ValidateScopes = true;
});

var host = builder.Build();

host.Run();
return host.RunAsync();
}
}
}