Azure 文件存储服务器响应状态为 400(不支持条件 headers。)

Azure File Storage the server responded with a status of 400 (Condition headers are not supported.)

我在 Azure 文件存储中存储了一些 png 文件,我正在从我的 MVC Web 项目中检索它并将其显示到浏览器。但有时我会从浏览器控制台收到以下错误消息。

Failed to load resource: the server responded with a status of 400 (Condition headers are not supported.)

如果我再次刷新页面,错误消息会自动消失。但这并没有解决我的问题,因为我再次 运行 我的 MVC 项目,同样的错误又回来了。如何解决?

这实际上是 Azure 存储上的一个常见问题,在官方参考文献Common REST API Error Codes中列出如下图。

表示Get File REST API does not support those request headers which not be listed in the Request Headers.

有一个类似的 SO 线程 ,它与您的问题相同。当您从 Azure 文件存储中获取文件时,它似乎在不同的浏览器中显示出不同的行为。

我无法通过带有 SAS 令牌的文件 url 重现此问题,但我真的建议您需要将这些静态文件(如图像)存储在 Azure Blob 存储上,正如我所知,这也是 Azure 最佳实践, 以其 url 和 sas 令牌或 public 容器显示图像。