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