我有一个ASP.NET Core 3.0项目。我正在从本地Data文件夹(在项目根目录中)(在wwwroot文件夹之外!)中读取一些数据。在本地运行时,可以通过“ IWebHostEnvironment.ContentRootPath”获得此路径。但是,将项目上载到Azure App Service时,ContentRootPath位于公共wwwroot文件夹中。托管在Azure App Service中时,如何访问Data文件夹?
答案 0 :(得分:1)
根据我的测试,Azure Web应用程序中的内容根路径为D:\home\site\wwwroot
,Azure Web应用程序中的webroot路径为D:\home\site\wwwroot\wwwroot
。因此,您可能会误解项目中的wwwroot
文件夹和Azure Web App上用于存储Web内容的wwwroot
文件夹。
我的HomeController
private readonly ILogger<HomeController> _logger;
private readonly IWebHostEnvironment _env;
public HomeController(ILogger<HomeController> logger, IWebHostEnvironment env)
{
_logger = logger;
_env = env;
}
public IActionResult Index()
{
string contentRootPath = _env.ContentRootPath;
string webRootPath = _env.WebRootPath;
return Content("Content Root Path: "+contentRootPath + "\nWeb Root Path: " + webRootPath);
}
我的网站网址:https://webv3.azurewebsites.net
关于这一点,我们也可以通过Kudo进行检查
有关更多详细信息,请参阅ContentRootPath different in Development and Azure web app