我们有一个 Blazor WASM 应用程序,托管在 azure 静态 Web 应用程序中。 我们有 2 个文件夹中的图像
/images
/data_images
/images 文件夹中的图像正在 Web 应用程序中加载,但 /data_images 中的图像未加载,我们得到 404。我已将相同的图像复制到 /data_images 文件夹中,但未加载。
我尝试重命名 data_images 文件夹名称,但这也不起作用
这是我的 staticwebapp.config.json
{
"trailingSlash": "auto",
"routes": [
],
"navigationFallback": {
"rewrite": "index.html",
"exclude": [ "/images/*.{png,jpg,gif,svg}", "/imagess/*.{png,jpg,gif,svg}", "/data_images/*", "/css/*" ]
},
"mimeTypes": {
".json": "text/json",
".png": "image/png",
".svg": "image/svg+xml"
}
}
在“staticwebapp.config.json”中,“/data_images/*”有一个“排除”规则,这意味着对“/data_images”文件夹的请求将从导航回退中排除到“index.html”。确保此排除不会阻止提供图像。如果您想从此文件夹中提供图像,则应删除此排除项。
这里我尝试过排除规则:
在index.razor页面
添加了图像@page "/"
<PageTitle>Index</PageTitle>
<h1>Hello, world!</h1>
Welcome to your new app.
<!-- Reference an image from the "/images" folder -->
<img src="/images/BrandBlazor.png" alt="BrandBlazor" />
<!-- Reference an image from the "/data_images" folder -->
<img src="/data_images/images.png" alt="images" />
<SurveyPrompt Title="How is Blazor working for you?" />
launchSettings.json
{
"trailingSlash": "auto",
"routes": [],
"navigationFallback": {
"rewrite": "index.html"
},
"mimeTypes": {
".json": "text/json",
".png": "image/png",
".svg": "image/svg+xml"
}
}
将代码部署到静态 Web 应用程序
结果
如果这有帮助,我也遇到了类似的问题。
我忘记在部署管道中打开
git-lfs
,这意味着图像的内容只是一些 git 文本,表明它确实存储在 lfs 中。