public class BorrowDataController : Controller
{
private readonly IHostingEnvironment _hostingEnvironment;
public BorrowDataController(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
[HttpGet]
public IActionResult test()
{
var path = Directory.GetCurrentDirectory();//获取当前的项目文件所在的目录。当使用命令启动时为执行dotnet命令所在的目录
dynamic type = (new Program()).GetType();
string currentDirectory = Path.GetDirectoryName(type.Assembly.Location);//获取应用程序的当前目录,即代码生成的dll文件所在目录
string webRootPath = _hostingEnvironment.WebRootPath;//获取项目下wwwroot文件夹的目录,如果没有在项目下新建wwwroot文件夹则返回空
string contentRootPath = _hostingEnvironment.ContentRootPath;//获取当前项目所在的文件夹
return Ok();
}
}