是否可以在没有IIS的情况下自托管ASP.NET Core应用程序? [英] Is it possible to self-host a 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屋!