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,