首页 > 解决方案 > 用于发布/订阅的 ASP.NET Core 动态端口

问题描述

我正在为 ASP.NET Core API 和多个 ASP.NET Core MVC 客户端创建 pub sub。所以我会有一些 API 计算,他们会将更改的数据发送到 API Pub/Sub 服务,然后发送到订阅的 MVC 客户端。我的问题是在我的 MVC 客户端应用程序中launchSettings.json有设置端口

"iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:50187", "sslPort": 44366 }

目前这就是我从 ASP Pub/Sub 服务连接到我的 MVC 客户端的原因

HttpClient client = new HttpClient();
string baseUrl = Configuration.GetValue<string>("AppSettings:BaseUrl");
client.BaseAddress = new Uri(baseUrl);
var contentType = new MediaTypeWithQualityHeaderValue("application/json");
client.DefaultRequestHeaders.Accept.Add(contentType);

HttpResponseMessage response = await 
client.GetAsync(employeesApiUrl + "/Create?model=" + "Ok");

所以这是我第一次在 ASP.NET Core 中编程,我想知道我的方法是否很好,如何制作动态端口,以便每个新客户端都有自己独特的端口?

标签: c#asp.netasp.net-mvcasp.net-core

解决方案


推荐阅读