问题描述
在通用主机生成器类( HostBuilder
)上,我看到2种几乎相同的扩展方法: ConfigureWebHostDefaults
和 ConfigureWebHost
.它们具有相同的签名,并且位于不同的程序集中.我在指南中看到了 ConfigureWebHostDefaults
,但是关于 ConfigureWebHost
几乎没有任何内容.它们之间有什么区别?
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?
推荐答案
通过ASP.NET Core源代码, ConfigureWebHostDefaults
等于:
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);
});
}
它只是调用 ConfigureWebHost
,但会执行一个附加步骤: ConfigureWebDefaults
.
It just calls the ConfigureWebHost
, but will an additional step: ConfigureWebDefaults
.
对于 ConfigureWebDefaults
,源代码相当长,并放置在此处:
As for ConfigureWebDefaults
, the source code is pretty long and placed here:
为了区别, ConfigureWebHostDefaults
使用以下命令配置Web主机:
For the difference, ConfigureWebHostDefaults
configures a web host with:
- 将Kestrel用作Web服务器,并使用应用程序的配置提供程序对其进行配置
- 添加HostFiltering中间件,
- 如果ASPNETCORE_FORWARDEDHEADERS_ENABLED = true,则添加ForwardedHeaders中间件,
- 启用IIS集成.
此外,官方文件提到:
这篇关于ConfigureWebHostDefaults和ConfigureWebHost方法之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!