.net core获取运行时文件绝对路径
作者:互联网
1、获取引用程序目录,即运行时代码目录
1 AppContext.BaseDirectory;
结果为:....\ApplicationName\bin\Debug\net5.0\
2、获取文件目录
1 using Microsoft.Extensions.Hosting; 2 3 private readonly IHostEnvironment _hostEnvironment; 4 5 public TestController(IHostEnvironment hostEnvironment) 6 { 7 _hostEnvironment = hostEnvironment; 8 } 9 10 public IActionResult Test() 11 { 13 return Content(_hostEnvironment.ContentRootPath); 14 }
结果为:
结果为:....\ApplicationName
标签:ApplicationName,core,获取,....,IHostEnvironment,绝对路径,public,net,hostEnvironment 来源: https://www.cnblogs.com/real9527/p/14704089.html