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

时间:2015-06-04 18:09:03

标签: iis rewrite

尝试让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>

1 个答案:

答案 0 :(得分:1)

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