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);
        }
    }

 

相关文章:

  • 2022-12-23
  • 2021-12-26
  • 2021-07-26
  • 2022-02-17
  • 2022-02-07
猜你喜欢
  • 2022-12-23
  • 2021-10-26
  • 2022-12-23
  • 2021-09-30
  • 2022-02-17
  • 2022-03-09
  • 2021-11-20
相关资源
相似解决方案