出站 IIS 重写规则以设置内容类型响应 Header

Outbound IIS Rewrite Rule to set Content Type Response Header

正在尝试让 IIS 将响应内容类型从 image/jpeg 重写为 application/octet-stream 以请求资源,如下所示:

http://www.example.org/path/to/images/some-image.jpg#download

以 application/octet-stream 的内容类型响应,以便浏览器提示下载。我尝试不必在应用程序中编写处理程序来执行此操作,而让 IIS 执行此操作会更容易。

这是我目前的情况:

<outboundRules>
    <rule name="Download Photos" preCondition="Photo Images">
        <match serverVariable="RESPONSE_CONTENT_TYPE" pattern="image/jpeg" />
        <action type="Rewrite" value="application/octet-stream" />
    </rule>
    <preConditions>
        <preCondition name="Photo Images">
            <add input="{REQUEST_LOCATION}" pattern="photos/.*\.jpg\?#download$" />
        </preCondition>
    </preConditions>
</outboundRules>

您的问题是 # 仅在浏览器中可用。服务器无法读取它。您可以在 Wiki 中阅读更多相关信息:https://en.wikipedia.org/wiki/Fragment_identifier