微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

http://localhost:8081/wordcount

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

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

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

http://localhost:8081/wordcount

http://localhost:8081/app1

http://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应用程序总是响应根http://localhost:8081/

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

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

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

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

http://mywebsite.com/app1

http://mywebsite.com/app2

非常感谢!

解决方法

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐