我的项目在本地主机上运行良好,但是当我将 Blazor WebAssembly 应用程序发布到 Azure 时,我得到:
Loading module from “https://aistorybuilderstest.azurewebsites.net/_framework/dotnet.js” was blocked because of a disallowed MIME type (“text/html”).
aistorybuilderstest.azurewebsites.net
Loading failed for the module with source “https://aistorybuilderstest.azurewebsites.net/_framework/dotnet.js”. aistorybuilderstest.azurewebsites.net:73:52
Uncaught (in promise) Error: Failed to start platform. Reason: TypeError: error loading dynamically imported module: https://aistorybuilderstest.azurewebsites.net/_framework/dotnet.js
mn https://aistorybuilderstest.azurewebsites.net/_framework/blazor.webassembly.js:1
这个项目在 Azure 上运行良好几个月,我只对 .razor 文件做了一个小更改。我还升级了 Nuget 软件包,但我回滚了所有这些更改,但它仍然无法工作。
我创建了一个新的 Blazor WebAssembly 项目并发布到 Azure,但它也无法工作。
它只是显示:
我不知道您的具体配置,也不知道配置在azure上如何工作。但我在我的自托管服务器上遇到了类似的问题。
在我的例子中,这是因为所有请求都被重写为index.html,这就是为什么它的mime类型为
text/html
。
要解决此问题,您可以从重写中排除 _framework 文件夹(以及一些更可能的文件夹,例如 _content)。
Nginx 有一个选项来查看文件是否存在,如果不存在则仅重写到 index.html:https://nginx.org/en/docs/http/ngx_http_core_module.html#try_files