如何在同一个 Azure Web App Service 中托管多个应用程序? [英] How to host multiple applications in the same Azure Web App Service?

查看:32
本文介绍了如何在同一个 Azure Web App Service 中托管多个应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想托管两个 ASP.NET Core 应用程序,一个 Web API 和一个 Blazor 服务器应用程序,但我在 Internet 上进行了搜索,我找到的答案只针对一个应用程序内部的不同路径,这不是我的情况.我会像使用同一个 Azure Web App 的子地址一样使用它们,例如:www.example.comwww.example.com/api,每个人都会成为不同的 .NET Core 应用程序.所以我怀疑我需要创建两个 Azure 应用服务并尝试将它们通信,但也许我想知道的结构不会以这种方式工作,对吗?我该怎么做?

解决方案

我的设置和你一样;一个 ASP.NET Core Web API 和一个 Blazor 服务器端应用程序.

由于您想为这两个服务使用相同的域,如果您要将请求路由到两个不同的 Azure 应用服务,则必须使用 Azure API 管理或其他代理.

一个更简单的选择是将两个服务部署到同一个应用服务,但作为 是否应该使用其他默认值.

您现在可以导航到两个不同的 URL 并点击每个服务.请注意,在开发 Web API 时,您不应将 api 添加到控制器路由中,因为此虚拟应用程序会为您执行此操作.

I would to host two ASP.NET Core Applications, a Web API and a Blazor Server App, but I searched in the internet and the answers that I founded only target to a different path inside of one application, that's not my case. I would to use they like a sub-address of the same Azure Web App for example: www.example.com and www.example.com/api where each one will be a different .NET Core application. So I suspect that I'll need to create two Azure App Services and try to communicate they both, but maybe the structured that I wonder won't work in this way, it's that right? How I can do this?

解决方案

I have the same setup as you; an ASP.NET Core web API, and a Blazor Server Side app.

As you want to use the same domain for both services, you would have to use Azure API Management or some other proxy if you were to route requests to two different Azure App Services.

An easier option is to deploy both services to the same App Service, but as different virtual applications. You publish your Blazor app as normal, but for the Web API you would publish to a new virtual application /api.

To enable this virtual application, navigate to Configuration and then Path mappings in your App Service. Here you already have the default virtual application / pointing to sitewwwroot. You then add another virtual application named /api pointing to sitewwwrootapi:

When adding the virtual application, remember to remove checkbox for Directory (making it a virtual application instead), and optionally enable Preload:

If you publish your app using Azure DevOps Pipeline, it has an option to specify virtual application if another than default should be used.

You can now navigate to your two different URLs and hit each service. Note that when developing your Web API, you should not add api to your controllers routes, as this virtual application does that for you.

这篇关于如何在同一个 Azure Web App Service 中托管多个应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆