The question is related to Blazor wasm hosted App.
I am resolving _webHostingEnvironment
in constructor of the controller.
_webHostingEnvironment = serviceProvider.GetRequiredService<IWebHostEnvironment>();
I am running into issue where I don't get correct value for the virtual director's physical path.
My app generates a QR code which I need to store in the images folder of virtual directory.
var webRootPath = "";
if (string.IsNullOrWhiteSpace(_webHostingEnvironment.WebRootPath))
webRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot");
else
webRootPath = _webHostingEnvironment.WebRootPath
Firstly _webHostingEnvironment.WebRootPath
is always null
, hence the code always gets the path from Directory.GetCurrentDirectory()
.
Directory.GetCurrentDirectory
provides the path of Server, but not the actual deployed path of wwwroot which is further down like /bin/debug/net6.0/wwwroot.
Here is the screenshot of the code in question
Now I could append that static path to get full path, but no sure what to use when I deploy it on Azure App Service or while using other deployment models