Sin*_*hus 2 iis url http-headers
我在 IIS7 服务器上有一个图片库。我想要一个按钮来强制下载当前可见的图像。
也许像设置一个 url 参数:http : //website.com/images/img.jpg?download
全局检测此参数,然后将 Content-Disposition 头设置为附件。
我的问题是,我该怎么做?我可以在 web.config 文件中以某种方式设置它吗?
我更像是一个前端的人。
小智 5
是的,您可以,但前提是您的服务器管理员允许您更改 Content-Disposition 标头。这可以在服务器或网站级别允许,但必须由管理员允许,因为它是通过 applicationHost.confg 文件配置的。
这是 web.config 的重写规则:
<outboundRules>
<rule name="Allow images to be downloaded" preCondition="Only match images">
<match serverVariable="RESPONSE_Content_Disposition" pattern="(.*)" negate="false" />
<action type="Rewrite" value="attachment" replace="true" />
<conditions>
<add input="{QUERY_STRING}" pattern="^download" />
</conditions>
</rule>
<preConditions>
<preCondition name="Only match images">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^image/" />
</preCondition>
</preConditions>
</outboundRules>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3856 次 |
| 最近记录: |