c# - 用于发布/订阅的 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 中编程,我想知道我的方法是否很好,如何制作动态端口,以便每个新客户端都有自己独特的端口?
解决方案
推荐阅读
- javascript - 如何将cloudinary图像同步转换为base64 img?
- css - CSS翻转卡-如何使正面小于背面
- javascript - 检查列表的所有项目是否都是整数字符串
- ruby-on-rails - 如何从目录外执行 docker compose?
- maps - 使用 Mapbox 进行地理编码
- html - CSS在悬停时放大网格图像,但将其周围的所有其他图像移开
- javascript - 使用反应、样式化组件等重新创建具有 n 行和列的动态 css 网格/flexbox 图像库
- java - Gradle:我可以使用 flatDir 存储库来包含源代码和/或 javadocs 吗?
- java - 为什么将一个子数组中的项目设置为另一个“超级数组”会更改子数组中的值(Mergesort)
- r - DPLYR:将多列从字符转换为整数