From a4599b835ecb8689393f9f4e9553636aa0734314 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Fri, 14 Jan 2022 18:12:09 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E4=B8=AD=E5=BF=83=E5=A4=B4=E5=83=8F=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/WebHostExtensions.cs | 17 +++++++++++++++++ .../Pages/Admin/Profiles.razor.cs | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/blazor/admin/BootstrapAdmin.Web/Extensions/WebHostExtensions.cs diff --git a/src/blazor/admin/BootstrapAdmin.Web/Extensions/WebHostExtensions.cs b/src/blazor/admin/BootstrapAdmin.Web/Extensions/WebHostExtensions.cs new file mode 100644 index 00000000..bc999ad6 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.Web/Extensions/WebHostExtensions.cs @@ -0,0 +1,17 @@ +namespace BootstrapAdmin.Web.Extensions; + +/// +/// +/// +public static class WebHostExtensions +{ + /// + /// + /// + /// + /// + /// + /// + public static string CombineLogoFile(this IWebHostEnvironment webHost, string logoFolder, string logoFile) => Path.Combine(webHost.WebRootPath, logoFolder.Replace("/", "\\").TrimStart('\\'), logoFile); + +} diff --git a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Profiles.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Profiles.razor.cs index b425e73f..953a5a48 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Profiles.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Profiles.razor.cs @@ -131,7 +131,7 @@ public partial class Profiles { // 保存到物理文件 var logoFile = $"{CurrentUser.UserName}{Path.GetExtension(file.OriginFileName)}"; - var fileName = Path.Combine(WebHost.WebRootPath, DefaultLogoFolder.Replace("/", "\\").TrimStart('\\'), logoFile); + var fileName = WebHost.CombineLogoFile(DefaultLogoFolder, logoFile); if (File.Exists(fileName)) { File.Delete(fileName); @@ -163,7 +163,7 @@ public partial class Profiles var logoFile = file.FileName; if (!string.IsNullOrEmpty(logoFile)) { - var fileName = Path.Combine(WebHost.WebRootPath, DefaultLogoFolder.Replace("/", "\\").TrimStart('\\'), logoFile); + var fileName = WebHost.CombineLogoFile(DefaultLogoFolder, logoFile); if (!logoFile.Equals(DefaultLogo, StringComparison.OrdinalIgnoreCase) && File.Exists(fileName)) { File.Delete(fileName);