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

编程入门 行业动态 更新时间:2024-10-21 03:34:30
本文介绍了是否可以在没有 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:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1595025.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   情况下   IIS   ASP   Core

发布评论

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

>www.elefans.com

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