ASP.NET 核心托管在 Windows 服务中 - 未提供静态文件(即 /wwwroot 的内容)

ASP.NET Core hosted in a Windows Service - static files not being served (i.e. contents of /wwwroot)

我有一个 ASP.NET 核心 v3.1 应用程序托管在 Windows 服务中。当我在本地 运行 服务时,一切都按预期工作。但是,当我发布它并将其部署到服务器时,静态文件(即 /wwwroot 文件夹的内容)没有被提供,例如

我的服务像这样存在于我的文件系统中,并且 wwwroot 包含所有必需的文件:

根据Microsoft documentation,我理解这是因为 Windows 服务的工作目录是 C:\Windows\system32 文件夹,这不是一个合适的文件夹放置 wwwroot 文件的地方。如何配置 wwwroot 文件夹的位置?

在 Startup.cs class Configure() 函数中,我需要添加以下内容:

app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(
        Path.Combine(workingDirectoryPath, "wwwroot"))
});

其中 'workingDirectoryPath' 是我的服务可执行文件所在目录的绝对路径,例如"C:\MyService"