是否可以在没有 IIS 的情况下自托管 ASP.NET Core 应用程序? [英] Is it possible to self-host an ASP.NET Core Application without IIS?
问题描述
我有一个完整的 ASP.NET MVC 应用程序(.NET Core、ASP.NET Core),它在 Visual Studio(使用 IISExpress)中运行良好.
I have a full-working ASP.NET MVC application (.NET Core, ASP.NET Core) which runs fine in Visual Studio (which uses IISExpress).
我现在想要一个控制台应用程序,它接受 ASP.NET Core 应用程序并托管它(自托管).
I would now like to have a console application which takes the ASP.NET Core application and hosts it (self hosting).
推荐答案
是否可以在没有 IIS 的情况下自托管 ASP.NET Core 应用程序?
Is it possible to self-host an ASP.NET Core Application without IIS?
是的.实际上,所有 ASP.NET Core 应用程序都是自托管的.即使在生产环境中,IIS/Nginx/Apache 也是自托管应用程序的反向代理.
Yes. In fact, all ASP.NET Core applications are self-hosted. Even in production, IIS/Nginx/Apache are a reverse proxy for the self-hosted application.
在相当标准的 Program.cs 类中,您可以看到自托管.IISIntegration
是可选的 - 只有当您想与 IIS 集成时才需要它.
In a reasonably standard Program.cs class, you can see the self-hosting. The IISIntegration
is optional - it's only necessary if you want to integrate with IIS.
public class Program
{
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddCommandLine(args)
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
.Build();
var host = new WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
这篇关于是否可以在没有 IIS 的情况下自托管 ASP.NET Core 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!