Sorry for a noob question, but it seems I can\'t get Server.MapPath from Controller. I need to output json file list from images folder at wwwroot. They are is at wwwroot/im
I know this has already been answered, but it has given me different results depending on my hosting environment (IIS Express vs IIS). The following approach seems to work for all hosting environments nicely if you want to get your wwwroot path (see this GitHub issue).
For example
private readonly IHostingEnvironment _hostEnvironment;
public ProductsController(IHostingEnvironment hostEnvironment)
{
_hostEnvironment = hostEnvironment;
}
[HttpGet]
public IEnumerable Get()
{
FolderScanner scanner = new FolderScanner(_hostEnvironment.WebRootPath);
return scanner.scan();
}