json - JSON 文件的 IIS 10 HTTP 响应 404
问题描述
我有一个不能从 IIS 10 提供的 JSON 文件。当我浏览它时,它总是返回 404.0 错误。我检查了 IIS 日志,请求是正确的路径。该文件位于 Web 目录结构中的指定位置。MIME 类型 .json 已添加为 application/json。我做了这两种不同的方式,使用 IIS 管理控制台,并通过使用删除后跟标签将其添加到 Web Config 来添加它。
我还在具有相同权限的同一目录中添加了其他文件类型、PNG、html。他们加载得很好。JSON 文件名为 translation-en.json。
我已经在 stackoverflow 上搜索了类似的问题,并尝试了我能找到的一切。对于需要使用 fetch 加载文件的组件,我已经与供应商合作。尝试了他们所有的建议。
我最近的尝试是安装 Failed-Request Tracing 并将其配置为记录所有响应 400-999 和详细输出,但我什么也没得到。如果我能做到这一点,我可能会学到一些东西。但没有运气。
Fiddler 仅显示来自服务器的简单 404 响应。
我正在使用 MS URL Rewrite 模块来处理路由。它的配置如下:
<rewrite>
<rules>
<rule name="Static Assets" stopProcessing="true">
<match url="([\S]+[.](html|htm|svg|js|json|css|png|gif|jpg|jpeg))" />
<action type="Rewrite" url="/{R:1}" />
</rule>
<rule name="ReactRouter Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
有趣的是,如果我打开目录浏览,我可以看到这些文件:
单击 test.png 可以正常工作。单击任何其他 .json 会导致 404 错误。
我完全处于静止状态。帮助?
解决方案
这是通过更改 URL 中静态内容的匹配模式来解决的,因此 json 位于 js 之前。
损坏的配置:([\S]+[.](html|htm|svg|js|json|css|png|gif|jpg|jpeg))
工作配置:([\S]+[.](html|htm|svg|json|js|css|png|gif|jpg|jpeg))
完成重写配置部分:
<rewrite>
<rules>
<rule name="Static Assets" stopProcessing="true">
<match url="([\S]+[.](html|htm|svg|json|js|css|png|gif|jpg|jpeg))" />
<action type="Rewrite" url="/{R:1}" />
</rule>
<rule name="ReactRouter Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
推荐阅读
- python - 其他文件中的类中的函数(python)
- javascript - 在 php 脚本代码中 document.createElement('p').textContent 不是 null 或类似的东西,但它不会显示创建的元素。为什么?
- android - Flutter 应用程序可以在配备 1GB Ram 的 Android Go 上运行吗?
- c# - 如果字符串完全符合定义,则匹配正则表达式
- apache-camel - Apache骆驼ThrottlingExceptionRoutePolicy失败重置
- sql - SQL 子查询 - 存在 - 任何 - 全部
- design-patterns - 用新技术重建初创公司代码库和架构
- influxdb - 计算 InfluxDB 平均值
- java - IntelliJ:错误:无法找到或加载主类
- validation - Joi 使用未知键验证对象