windows下路徑為:"xxxx\\yyyy"
linux路徑下為:"xxxx/yyyy"
用Path.Combine("xxxx","yyyy");進行合並
-------------------------------------------------
通過nuget引入包 System.Runtime.InteropServices
RuntimeInformation.IsOSPlatform(OSPlatform.Linux)//判斷是否為Liunx
RuntimeInformation.IsOSPlatform(OSPlatform.Windows)/判斷是否為Win
RuntimeInformation.IsOSPlatform(OSPlatform.OSX)/判斷是否為OS
----------------------------------------
docker環境下用Environment.CurrentDirectory,不要用AppDomain.CurrentDomain.BaseDirectory
----------------------------------------------------
Web根目錄和內容根目錄
public class HomeController : Controller { private readonly IHostingEnvironment _hostingEnvironment; public HomeController(IHostingEnvironment hostingEnvironment) { _hostingEnvironment = hostingEnvironment; } public ActionResult Index() { string webRootPath = _hostingEnvironment.WebRootPath; string contentRootPath = _hostingEnvironment.ContentRootPath; return Content(null); } }