From f78c3a0e0d8ebc11b631a358056d3ca4e81c8c2f Mon Sep 17 00:00:00 2001 From: xRain Date: Wed, 10 Jul 2024 06:35:19 +0800 Subject: [PATCH] =?UTF-8?q?fix=20fullurl=20=E4=B8=8D=E6=8A=9B=E5=87=BA?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Helpers/SimApiStorage.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Helpers/SimApiStorage.cs b/Helpers/SimApiStorage.cs index 8c2a68c..5114afb 100644 --- a/Helpers/SimApiStorage.cs +++ b/Helpers/SimApiStorage.cs @@ -127,6 +127,27 @@ public class SimApiStorage return path.StartsWith('~') ? string.Concat(url, path.AsSpan(1, path.Length - 1)) : $"{ServeUrl}{path}"; } + /// + /// 获取一个Path得访问URL + /// + /// + /// + public string? GetUrl(string? path) + { + if (string.IsNullOrEmpty(path)) return path; + if (path.StartsWith("~/")) + { + var httpRequest = HttpContextAccessor.HttpContext?.Request; + var url = $"{httpRequest?.Scheme}://{httpRequest?.Host}"; + return string.Concat(url, path.AsSpan(1, path.Length - 1)); + } + if (path.StartsWith('/')) + { + return $"{ServeUrl}{path}"; + } + return path; + } + /// /// 从URL中获取相对路径 (如果url不是当前服务器的url,则原样返回) ///