asp.net core中獲取路徑方式


        /// <summary>
        /// CORE中獲取路徑
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetPath()
        {
            return Ok(new {
                //通過IWebHostEnvironment獲取當前Web根和內容根
                AppName = hostingEnvironment.ApplicationName,
                ContentRootPath =hostingEnvironment.ContentRootPath,
                WebRootPath = hostingEnvironment.WebRootPath,
                EnvironmentName = hostingEnvironment.EnvironmentName,
                //獲取當前目錄
                dir = Directory.GetCurrentDirectory(),
                //獲取DLL所在路徑
                appPath= Microsoft.DotNet.PlatformAbstractions.ApplicationEnvironment.ApplicationBasePath
          path=AppDomain.CurrentDomain.BaseDirectory }); }

輸出如下:

{
  "appName": "Shop.API",
  "contentRootPath": "E:\\Teaching\\ShopManageSystem\\Shop.API",
  "webRootPath": "E:\\Teaching\\ShopManageSystem\\Shop.API\\wwwroot",
  "environmentName": "Development",
  "dir": "E:\\Teaching\\ShopManageSystem\\Shop.API",
  "appPath": "E:\\Teaching\\ShopManageSystem\\Shop.API\\bin\\Debug\\netcoreapp3.1\\"
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM