我有一个 ASP.NET Core 3.0 项目。我正在从本地数据文件夹(在项目的根目录中)(在 wwwroot 文件夹之外!)读取一些数据。在本地运行时,我可以使用“IWebHostEnvironment.ContentRootPath”获取此路径。但是,将项目上传到 Azure 应用服务时,ContentRootPath 位于公共(public) wwwroot 文件夹中。当托管在 Azure 应用服务中时,如何访问数据文件夹?
最佳答案
根据我的测试,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
关于c# - Azure 应用服务中的 IWebHostEnvironment ContentRootPath 与本地不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59308147/