/// <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\\" }