1
This commit is contained in:
52
iMES.Core/BaseProvider/ServerMapPath/PathProvider.cs
Normal file
52
iMES.Core/BaseProvider/ServerMapPath/PathProvider.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System.IO;
|
||||
using iMES.Core.Extensions;
|
||||
using iMES.Core.Extensions.AutofacManager;
|
||||
|
||||
namespace iMES.Core.BaseProvider.ServerMapPath
|
||||
{
|
||||
public interface IPathProvider : IDependency
|
||||
{
|
||||
string MapPath(string path);
|
||||
string MapPath(string path, bool rootPath);
|
||||
IWebHostEnvironment GetHostingEnvironment();
|
||||
}
|
||||
|
||||
public class PathProvider : IPathProvider
|
||||
{
|
||||
private IWebHostEnvironment _hostingEnvironment;
|
||||
|
||||
public PathProvider(IWebHostEnvironment environment)
|
||||
{
|
||||
_hostingEnvironment = environment;
|
||||
}
|
||||
public IWebHostEnvironment GetHostingEnvironment()
|
||||
{
|
||||
return _hostingEnvironment;
|
||||
}
|
||||
|
||||
public string MapPath(string path)
|
||||
{
|
||||
return MapPath(path, false);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="rootPath">获取wwwroot路径</param>
|
||||
/// <returns></returns>
|
||||
public string MapPath(string path, bool rootPath)
|
||||
{
|
||||
if (rootPath)
|
||||
{
|
||||
if (_hostingEnvironment.WebRootPath == null)
|
||||
{
|
||||
_hostingEnvironment.WebRootPath = _hostingEnvironment.ContentRootPath + "/wwwroot".ReplacePath();
|
||||
}
|
||||
return Path.Combine(_hostingEnvironment.WebRootPath, path).ReplacePath();
|
||||
}
|
||||
return Path.Combine(_hostingEnvironment.ContentRootPath, path).ReplacePath();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user