From 7480e821c3f6e695f8977027145abdc552cc81d5 Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Fri, 28 Sep 2018 09:54:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9BUG=EF=BC=9A=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E4=B8=AD=E5=BF=83=E9=A1=B5=E9=9D=A2=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E6=97=B6=E8=8E=B7=E5=BE=97=E7=94=A8=E6=88=B7=E5=A4=B4?= =?UTF-8?q?=E5=83=8F=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/Models/ProfilesModel.cs | 10 ++++------ Bootstrap.Admin/wwwroot/js/profiles.js | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Bootstrap.Admin/Models/ProfilesModel.cs b/Bootstrap.Admin/Models/ProfilesModel.cs index b30cea60..0da3d104 100644 --- a/Bootstrap.Admin/Models/ProfilesModel.cs +++ b/Bootstrap.Admin/Models/ProfilesModel.cs @@ -1,8 +1,5 @@ -using Bootstrap.DataAccess; -using Bootstrap.Security; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; using System.IO; namespace Bootstrap.Admin.Models @@ -22,8 +19,9 @@ namespace Bootstrap.Admin.Models /// public ProfilesModel(ControllerBase controller) : base(controller) { - // TODO: 找到MapPath方法 - var fileName = AppContext.BaseDirectory + Icon; + var host = controller.HttpContext.RequestServices.GetService(typeof(IHostingEnvironment)) as IHostingEnvironment; + if (host == null) return; + var fileName = Path.Combine(host.WebRootPath, Icon.TrimStart('~', '/').Replace('/', '\\')); if (File.Exists(fileName)) { Size = new FileInfo(fileName).Length; diff --git a/Bootstrap.Admin/wwwroot/js/profiles.js b/Bootstrap.Admin/wwwroot/js/profiles.js index 32879458..99c2cb45 100644 --- a/Bootstrap.Admin/wwwroot/js/profiles.js +++ b/Bootstrap.Admin/wwwroot/js/profiles.js @@ -12,7 +12,7 @@ preIcon ], initialPreviewConfig: [ - { caption: "现在头像", size: $('#fileIcon').attr('data-init'), showZoom: true }, + { caption: "现在头像", size: $('#fileIcon').attr('data-init'), showZoom: true } ], initialPreviewAsData: true, overwriteInitial: true,