如何在Azure Service Fabric的共享群集上,针对相同端口使用子路径部署Asp.Net Core应用程序?

2026-03-30 12:181阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计427个文字,预计阅读时间需要2分钟。

如何在Azure Service Fabric的共享群集上,针对相同端口使用子路径部署Asp.Net Core应用程序?

Service Fabric 类似于 wordcount、Web 应用程序,可以侦听子路径中的端口,如下所示:

+ http://localhost:8081/wordcount

此配置的代码是:

csharp// 请参考GitHub: https://github.com/Azure-Samples/service-fabric-dotnet-getting-started/blob/m

Service Fabric样本如wordcount,web应用程序侦听子路径中的端口,如下所示:

localhost:8081/wordcount

此配置的代码是:(请参阅GitHub github.com/Azure-Samples/service-fabric-dotnet-getting-started/blob/master/Services/WordCount/WordCount.WebService/WordCountWebService.cs上的文件)

如何在Azure Service Fabric的共享群集上,针对相同端口使用子路径部署Asp.Net Core应用程序?

protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners() { return new[] { new ServiceInstanceListener(initParams => new OwinCommunicationListener("wordcount", new Startup(), initParams)) }; }

使用此配置,我们可以使用相同的端口在同一群集上部署其他Web应用程序(8081)

localhost:8081/wordcount

localhost:8081/app1

localhost:8081/app2

等等.

但Asp.Net Core项目模板不同,我不知道如何在侦听器配置上添加子路径.

下面的代码是我们在项目模板(Program.cs类WebHostingService)中的代码:

protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners() { return new[] { new ServiceInstanceListener(_ => this) }; } Task<string> ICommunicationListener.OpenAsync(CancellationToken cancellationToken) { var endpoint = FabricRuntime.GetActivationContext().GetEndpoint(_endpointName); string serverUrl = $"{endpoint.Protocol}://{FabricRuntime.GetNodeContext().IPAddressOrFQDN}:{endpoint.Port}"; _webHost = new WebHostBuilder().UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup<Startup>() .UseUrls(serverUrl) .Build(); _webHost.Start(); return Task.FromResult(serverUrl); }

语义有点不同,但都在同一点上结束.
问题是,即使我在serverUrl的末尾添加子路径它也不起作用,Web应用程序总是响应根localhost:8081/

看看我在下面的代码段中尝试过的方式:

string serverUrl = $"{endpoint.Protocol}://{FabricRuntime.GetNodeContext().IPAddressOrFQDN}:{endpoint.Port}/app1";

如何使用asp.net核心获得与“经典”Web应用程序相同的结果?

目标是在端口80上的azure上发布,以便让用户获得更好的体验,例如:

mywebsite.com/app1

mywebsite.com/app2

非常感谢!

Kestrel不支持多个应用程序之间的URL前缀或端口共享.你必须使用 WebListener:

使用Microsoft.AspNetCore.Hosting…_webHost = new WebHostBuilder().UseWebListener()

标签:

本文共计427个文字,预计阅读时间需要2分钟。

如何在Azure Service Fabric的共享群集上,针对相同端口使用子路径部署Asp.Net Core应用程序?

Service Fabric 类似于 wordcount、Web 应用程序,可以侦听子路径中的端口,如下所示:

+ http://localhost:8081/wordcount

此配置的代码是:

csharp// 请参考GitHub: https://github.com/Azure-Samples/service-fabric-dotnet-getting-started/blob/m

Service Fabric样本如wordcount,web应用程序侦听子路径中的端口,如下所示:

localhost:8081/wordcount

此配置的代码是:(请参阅GitHub github.com/Azure-Samples/service-fabric-dotnet-getting-started/blob/master/Services/WordCount/WordCount.WebService/WordCountWebService.cs上的文件)

如何在Azure Service Fabric的共享群集上,针对相同端口使用子路径部署Asp.Net Core应用程序?

protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners() { return new[] { new ServiceInstanceListener(initParams => new OwinCommunicationListener("wordcount", new Startup(), initParams)) }; }

使用此配置,我们可以使用相同的端口在同一群集上部署其他Web应用程序(8081)

localhost:8081/wordcount

localhost:8081/app1

localhost:8081/app2

等等.

但Asp.Net Core项目模板不同,我不知道如何在侦听器配置上添加子路径.

下面的代码是我们在项目模板(Program.cs类WebHostingService)中的代码:

protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners() { return new[] { new ServiceInstanceListener(_ => this) }; } Task<string> ICommunicationListener.OpenAsync(CancellationToken cancellationToken) { var endpoint = FabricRuntime.GetActivationContext().GetEndpoint(_endpointName); string serverUrl = $"{endpoint.Protocol}://{FabricRuntime.GetNodeContext().IPAddressOrFQDN}:{endpoint.Port}"; _webHost = new WebHostBuilder().UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup<Startup>() .UseUrls(serverUrl) .Build(); _webHost.Start(); return Task.FromResult(serverUrl); }

语义有点不同,但都在同一点上结束.
问题是,即使我在serverUrl的末尾添加子路径它也不起作用,Web应用程序总是响应根localhost:8081/

看看我在下面的代码段中尝试过的方式:

string serverUrl = $"{endpoint.Protocol}://{FabricRuntime.GetNodeContext().IPAddressOrFQDN}:{endpoint.Port}/app1";

如何使用asp.net核心获得与“经典”Web应用程序相同的结果?

目标是在端口80上的azure上发布,以便让用户获得更好的体验,例如:

mywebsite.com/app1

mywebsite.com/app2

非常感谢!

Kestrel不支持多个应用程序之间的URL前缀或端口共享.你必须使用 WebListener:

使用Microsoft.AspNetCore.Hosting…_webHost = new WebHostBuilder().UseWebListener()

标签: