无法使用 URL 从服务器明确查看 json 文件,它告诉文件未找到
Cannot view a json file explicitly from the server using URL its telling File not Found
我已经在服务器中为我的 asp.net 项目上传了一个 manifest.json 文件,但是当我使用 URL 显式调用它时我无法查看文件的内容,而我可以查看同一目录中的其他文件,例如 css 和 js 文件
这是我的 manifest.json 文件代码
{
"name": "Example Foo",
"short_name": "Example",
"version": "0.0.0.1",
"manifest_version": 2,
"icons": [
{
"src": "../content/themes/img/logos/launcher-icon-0-75x.png",
"sizes": "36x36",
"type": "image/png",
"density": 0.75
},
{
"src": "../content/themes/img/logos/launcher-icon-1x.png",
"sizes": "48x48",
"type": "image/png",
"density": 1.0
},
{
"src": "../content/themes/img/logos/launcher-icon-1-5x.png",
"sizes": "72x72",
"type": "image/png",
"density": 1.5
},
{
"src": "../content/themes/img/logos/launcher-icon-2x.png",
"sizes": "96x96",
"type": "image/png",
"density": 2.0
},
{
"src": "../content/themes/img/logos/launcher-icon-3x.png",
"sizes": "144x144",
"type": "image/png",
"density": 3.0
},
{
"src": "../content/themes/img/logos/launcher-icon-4x.png",
"sizes": "192x192",
"type": "image/png",
"density": 4.0
}
],
"start_url": "/home/index.cshtml",
"display": "standalone",
"orientation": "portrait",
"lang": "en"
}
我上传到服务器了。现在,当我尝试使用 url 显式调用它时,例如 www.example.com/manifest.json 然后它会给出一个错误提示找不到文件,而如果我使用 localhost 显式调用它url 点赞 localhost:6453/manifest.json 这样我就可以看到内容了 我该怎么办?
您必须在 web.config
中允许 JSON
个文件
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
您可以查看 this article 以获得有关如何添加 mime 类型的更详细说明。
在某些情况下,这会与 applicationhost.config
文件中的相同 MIME 映射产生冲突。如果是这样,那么您必须先删除 fileExtension
,如下所示:
<system.webServer>
<staticContent>
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
我已经在服务器中为我的 asp.net 项目上传了一个 manifest.json 文件,但是当我使用 URL 显式调用它时我无法查看文件的内容,而我可以查看同一目录中的其他文件,例如 css 和 js 文件 这是我的 manifest.json 文件代码
{
"name": "Example Foo",
"short_name": "Example",
"version": "0.0.0.1",
"manifest_version": 2,
"icons": [
{
"src": "../content/themes/img/logos/launcher-icon-0-75x.png",
"sizes": "36x36",
"type": "image/png",
"density": 0.75
},
{
"src": "../content/themes/img/logos/launcher-icon-1x.png",
"sizes": "48x48",
"type": "image/png",
"density": 1.0
},
{
"src": "../content/themes/img/logos/launcher-icon-1-5x.png",
"sizes": "72x72",
"type": "image/png",
"density": 1.5
},
{
"src": "../content/themes/img/logos/launcher-icon-2x.png",
"sizes": "96x96",
"type": "image/png",
"density": 2.0
},
{
"src": "../content/themes/img/logos/launcher-icon-3x.png",
"sizes": "144x144",
"type": "image/png",
"density": 3.0
},
{
"src": "../content/themes/img/logos/launcher-icon-4x.png",
"sizes": "192x192",
"type": "image/png",
"density": 4.0
}
],
"start_url": "/home/index.cshtml",
"display": "standalone",
"orientation": "portrait",
"lang": "en"
}
我上传到服务器了。现在,当我尝试使用 url 显式调用它时,例如 www.example.com/manifest.json 然后它会给出一个错误提示找不到文件,而如果我使用 localhost 显式调用它url 点赞 localhost:6453/manifest.json 这样我就可以看到内容了 我该怎么办?
您必须在 web.config
JSON
个文件
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
您可以查看 this article 以获得有关如何添加 mime 类型的更详细说明。
在某些情况下,这会与 applicationhost.config
文件中的相同 MIME 映射产生冲突。如果是这样,那么您必须先删除 fileExtension
,如下所示:
<system.webServer>
<staticContent>
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>