Reputation: 123
I see 2 nearly the same extension methods on generic host builder class (HostBuilder
): ConfigureWebHostDefaults
and ConfigureWebHost
. They have the same signature and locate in different assemblies. I saw ConfigureWebHostDefaults
in guides but there is nearly nothing about ConfigureWebHost
. What is the difference between them?
Upvotes: 11
Views: 16579
Reputation: 3737
Via ASP.NET Core source code, ConfigureWebHostDefaults
equals to:
public static IHostBuilder ConfigureWebHostDefaults(this IHostBuilder builder, Action<IWebHostBuilder> configure)
{
return builder.ConfigureWebHost(webHostBuilder =>
{
WebHost.ConfigureWebDefaults(webHostBuilder);
configure(webHostBuilder);
});
}
It just calls the ConfigureWebHost
, but will an additional step: ConfigureWebDefaults
.
As for ConfigureWebDefaults
, the source code is pretty long and placed here:
For the difference, ConfigureWebHostDefaults
configures a web host with:
Also, the official document mentioned that:
The ConfigureWebHostDefaults method loads host configuration from environment variables prefixed with "ASPNETCORE_". Sets Kestrel server as the web server and configures it using the app's hosting configuration providers. For the Kestrel server's default options, see Kestrel web server implementation in ASP.NET Core. Adds Host Filtering middleware. Adds Forwarded Headers middleware if ASPNETCORE_FORWARDEDHEADERS_ENABLED=true. Enables IIS integration. For the IIS default options, see Host ASP.NET Core on Windows with IIS.
Document link: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-3.0#default-builder-settings
Upvotes: 21