[英]Error 500: Hosting .net Core 6 app into IIS on Windows Server 2016
[英]What should my MVC Core app's Program class look like for hosting in IIS?
目前, Program
类是MVC Application项目模板创建的默认类,如下所示:
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
我知道我也应该在那里有一个UseIISIntegration
调用,并且应该以某种方式参与Kestrel
,但是我仅此而已。
有人可以给我一个例子,说明我的MVC应用程序已正确配置为在IIS上托管时, Program
类的内容应按什么顺序排列。 Windows上带有IIS的Windows上的MS Docs Host ASP.NET Core主题仅具有以下不足的示例:
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
...
习惯于在Asp.Net Core 1.x中启用IISIntegration组件时
var host = new WebHostBuilder()
.UseKestrel()
.UseIISIntegration()
...
因为同时需要UseKestrel
和UseIISIntegration
。
在最新版本的Asp.Net Core 2.x中,已将其合并到WebHost.CreateDefaultBuilder
方法中
以下默认值应用于返回的WebHostBuilder:使用Kestrel作为Web服务器,将ContentRootPath设置为GetCurrentDirectory()的结果,从“ appsettings.json”和“ appsettings。[EnvironmentName] .json”加载IConfiguration,从使用入口程序集将EnvironmentName设为“开发”,从环境变量加载IConfiguration,将ILoggerFactory配置为登录到控制台并调试输出,启用IIS集成,使框架能够将其选项绑定到其默认配置部分的功能时,用户的秘密并在EnvironmentName为'Development'时添加开发人员例外页面
再次引用文档
典型的Program.cs调用
CreateDefaultBuilder
来开始设置主机。CreateDefaultBuilder
将Kestrel配置为Web服务器,并通过配置ASP.NET Core模块的基本路径和端口来启用IIS集成。
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
...
In Asp.Net Core 1.x as you are accustom to when enabling the IISIntegration components you would have done
var host = new WebHostBuilder()
.UseKestrel()
.UseIISIntegration()
...
ASP.NET Core 2.x仍然支持使用WebHostBuilder
。
Windows上具有IIS的参考主机ASP.NET Core
有关在Asp.Net Core中托管的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.