asp.net – 无法使用URL告知服务器显式查看json文件,告知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"
}

我把它上传到服务器.现在当我尝试使用像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>
点赞