部署到 IIS 后,Blazor 不提供来自 wwwroot 的静态文件

问题描述

我正在开发一个 .net 5.0 blazor wasm 应用程序。当我使用 IIS Express 运行应用表单 Visual Studio 并导航到 https://localhost:5001/docs/simple.pdf 时,该文件在浏览器中提供。

但是,在将 blazor wasm 应用程序部署到 IIS 后,同样的操作不起作用。我没有收到任何错误,而是我的 Not Found 路线模板屏幕被加载。

这是屏幕打印:

wwwroot blazor wasm 应用:

enter image description here

IISExpress 加载文档:

enter image description here

IIS virtual directory 路径:

enter image description here

IIS 未加载文档并显示 NotFound 路线模板:

enter image description here

我还注意到 wwwroot 中的所有文件都不能在 IIS 的浏览器中直接访问。请帮助我解决我所缺少的。

解决方法

Blazor WebAssembly 不参与提供您的文件。

这是需要在 IIS 中配置的内容。

,

我能够重现您的问题。这是我认为您可以修复它的方法。

导航到解决方案中的服务器项目。

打开文件 Startup.cs。导航到 Configure 方法并添加以下代码行:

    app.UseStaticFiles();

发布您的项目并重新复制到 IIS。

在默认的 Visual Studio 模板中,此代码将在那里。但是,根据您创建解决方案的方式,您可能错过了。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...