2

I've an ASP.NET Core 3.0 project. I'm reading some data from local Data folder (in root of project) (outside wwwroot folder!). When running local, I can get this path with ' IWebHostEnvironment.ContentRootPath'. However, when uploading the project to Azure App Service, ContentRootPath is located in public wwwroot folder. How can I access the Data folder when hosted in Azure App Service?

LPLN
  • 475
  • 1
  • 6
  • 20
Sven Nijs
  • 498
  • 3
  • 19
  • This answer might help: https://stackoverflow.com/questions/52117825/unable-to-load-static-file-once-it-has-been-published-to-azure-using-asp-net-co – Bloggrammer Dec 10 '20 at 01:40

1 Answers1

2

According to my test, the content root path in Azure Web app is D:\home\site\wwwroot and the webroot path in Azure web app is D:\home\site\wwwroot\wwwroot. So you may misunderstand the wwwroot folder in your project with the wwwroot folder on Azure Web App for storing your web content.

My 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);
        }

My website url: https://webv3.azurewebsites.net enter image description here

Regarding that, we also can check it via Kudo enter image description here enter image description here enter image description here

For more details, please refer to ContentRootPath different in Development and Azure web app

Community
  • 1
  • 1
Jim Xu
  • 21,610
  • 2
  • 19
  • 39