I have deployed a ASP.NET MVC 6 website to Azure from Git. Details of the deployment can be found in this blog post but basically I use DNU to publish it and then kudu to push it to an Azure website.
Using IHostingEnvironment
I get the ApplicationBasePath. The problem is that the paths I get back are very different on localhost and on Azure.
Azure: "D:\home\site\approot\src\src"
Localhost: "C:\Users\deebo\Source\mysite\site\src"
I want to use the base path to get the full path to a folder containing some images: wwwroot/img/gallery/
I got around this with the following code:
var rootPath = _appEnvironment.ApplicationBasePath;
var pathFix = "../../../";
if(_hostingEnvironment.IsDevelopment())
{
pathFix = string.Empty;
}
var imagesPath = Path.Combine(rootPath, pathFix, "wwwroot", "img", "gallery");
This may work but seems hacky.
Is it possible my deployment method impacts on this?
Is there a more consistent way to get the application path?