iis - IIS 删除图像的 nosniff 标头
问题描述
我有一个返回图像的 API,例如:
/api/products/images/233 -> 这将返回一个 233.jpg 图像
但是我的 IIS 有一条规则将 X-Content-Type-Options 标头添加到安全请求中,但这会破坏 Internet Explorer 上的图像,因此当端点 /products/images/ 是时,我需要一种方法来删除此规则仅当它不是那个端点时才调用或添加标头的方法。
我尝试将其用于自定义标题
但它没有用,我试过这样:
<system.webServer>
<rewrite>
<outboundRules>
<rule name="Remove nosniff">
<match serverVariable="RESPONSE_X_Content_Type_Options" pattern="/products/images/" />
<action type="Rewrite" value="none"/>
</rule>
</outboundRules>
</rewrite>
</system.webServer>
但它并没有改变任何东西,图像仍然有“nosniff”标题。
我错过了一些配置吗?还是有另一种方法可以做到这一点?
解决方案
您的匹配条件是检查标头是否RESPONSE_X_Content_Type_Options
包含值/products/images/
而不是nosniff
. 您可以使用 Location 块将此规则限制为/products/images/
,然后用于pattern="nosniff"
查找值nosniff
<configuration>
...
<system.webServer/>
...
<location path="products/images/">
<system.webServer>
<rewrite>
<outboundRules>
<rule name="Remove nosniff">
<match serverVariable="RESPONSE_X_Content_Type_Options" pattern="nosniff" />
<action type="Rewrite" value="none"/>
</rule>
</outboundRules>
</rewrite>
</system.webServer>
</location>
</configuration>
有关元素,请参阅文档:https ://msdn.microsoft.com/en-us/library/b6x6shw7(v=vs.100).aspx
推荐阅读
- python - 我正在尝试制作一个简单的故事制作者,但我被性别部分困住了
- kubernetes - k0s kubectl exec 和 kubectl 端口转发被破坏
- python - 基于 Python Pandas 中的比较,比较 DataFrame 列并将另外两列添加到 DataFrame
- solr - 无法在 solr 4.10 中恢复备份
- sql - 使用多个联接时如何正确使用 COUNT()?
- sql - 在动态 SQL 中,未创建表
- asp.net-core - 在组件文档中添加TagHelper
- firebase - 从 Firestore 的集合中获取多个特定数据的最佳方法是什么?
- html - iFrame 不显示 PDF 页面
- performance - 如何使用 pyspark 提高 csv 到 parquet 文件格式的性能?