是否可以在没有IIS的情况下自托管ASP.NET Core应用程序?

编程入门 行业动态 更新时间:2024-10-20 20:45:02
本文介绍了是否可以在没有IIS的情况下自托管ASP.NET Core应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个可以正常运行的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应用程序?

本文发布于:2023-11-15 13:53:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1595026.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   情况下   IIS   ASP   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!