1

该问题与 Blazor wasm 托管应用程序有关。

我正在_webHostingEnvironment控制器的构造函数中解析。

_webHostingEnvironment = serviceProvider.GetRequiredService<IWebHostEnvironment>();

我遇到了一个问题,我没有为虚拟导演的物理路径获得正确的值。

我的应用程序会生成一个 QR 码,我需要将其存储在虚拟目录的 images 文件夹中。

var webRootPath = "";
if (string.IsNullOrWhiteSpace(_webHostingEnvironment.WebRootPath))
     webRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot");
else
   webRootPath = _webHostingEnvironment.WebRootPath

首先_webHostingEnvironment.WebRootPath是总是null,因此代码总是从Directory.GetCurrentDirectory().

Directory.GetCurrentDirectory提供服务器的路径,但不提供 wwwroot 的实际部署路径,如 /bin/debug/net6.0/wwwroot。

这是有问题的代码的屏幕截图

在此处输入图像描述

现在我可以附加该静态路径以获得完整路径,但不确定在 Azure App Service 上部署它或使用其他部署模型时使用什么

4

0 回答 0