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