From a2b55742c64f4b2c9e6bd85ed3733adccdec48de Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期五, 13 三月 2026 14:37:27 +0800
Subject: [PATCH] fix: 修复Web页面HttpClient依赖注入问题
---
Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/Pages/Create.cshtml.cs | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/Pages/Create.cshtml.cs b/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/Pages/Create.cshtml.cs
index 928a997..2ddd774 100644
--- a/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/Pages/Create.cshtml.cs
+++ b/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/Pages/Create.cshtml.cs
@@ -12,13 +12,12 @@
public class CreateModel : PageModel
{
private readonly ILogger<CreateModel> _logger;
- private readonly HttpClient _httpClient;
+ private readonly IHttpClientFactory _httpClientFactory;
public CreateModel(ILogger<CreateModel> logger, IHttpClientFactory httpClientFactory)
{
_logger = logger;
- _httpClient = httpClientFactory.CreateClient();
- _httpClient.BaseAddress = new Uri($"{Request.Scheme}://{Request.Host}");
+ _httpClientFactory = httpClientFactory;
}
[BindProperty]
@@ -38,6 +37,10 @@
try
{
+ // 鍒涘缓HttpClient骞惰缃瓸aseAddress
+ var httpClient = _httpClientFactory.CreateClient();
+ httpClient.BaseAddress = new Uri($"{Request.Scheme}://{Request.Host}");
+
var config = new InstanceConfig
{
Id = Input.Id,
@@ -58,7 +61,7 @@
}
};
- var response = await _httpClient.PostAsJsonAsync("/api/SimulatorInstances", config);
+ var response = await httpClient.PostAsJsonAsync("/api/SimulatorInstances", config);
if (response.IsSuccessStatusCode)
{
--
Gitblit v1.9.3