How to consistently get application base path for ASP.NET 5 DNX project on both production and development environment? How to consistently get application base path for ASP.NET 5 DNX project on both production and development environment? azure azure

How to consistently get application base path for ASP.NET 5 DNX project on both production and development environment?


You can use the IHostingEnvironment.WebRootPath. From the Asp 5 deep dive:

The IHostingEnvironment services gives you access to the Web root path for your application (typically your www folder) and also an IFileProvider abstraction for your Web root.

So you can get the wwwroot path or even directly map a path:

var wwwrootPath = env.WebRootPath;var imagesPath = hostingEnv.MapPath("img/gallery");

PS. I tried this locally, not on Azure. However I haven't found any mention about issues in Azure. This answer even mentions that in Azure IHostingEnvironment.WebRootPath will point to D:/Home/site/wwwroot.