如何在 IIS 中强制下载 .mp3 和 .mp4 文件
我有一个专用文件夹,当.mp4
文件需要下载时(而不是在浏览器窗口中流式传输)。
该文件夹中的此Web.config文件为我做到了:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<outboundRules>
<remove name="Remove Server Response Header" />
<rule name="Remove Server Response Header" enabled="true">
<match serverVariable="RESPONSE_SERVER" pattern=".*" />
<conditions />
<action type="Rewrite" />
</rule>
<rule name="Force Download For MP4s" preCondition="FileIsMP4">
<match serverVariable="RESPONSE_Content-Disposition" pattern=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" matchType="Pattern" pattern="(.*)\\([^/]+)\.mp4$" ignoreCase="true" negate="false" />
</conditions>
<action type="Rewrite" value="Value: attachment; filename={C:2}.mp4" />
</rule>
<preConditions>
<preCondition name="FileIsMP4">
<add input="{REQUEST_FILENAME}" pattern="\.mp4$" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<staticContent>
<remove fileExtension=".mp3" />
<remove fileExtension=".mp4" />
<remove fileExtension=".m4v" />
<remove fileExtension=".avi" />
<remove fileExtension=".mov" />
<mimeMap fileExtension=".mov" mimeType="application/octet-stream" />
<mimeMap fileExtension=".avi" mimeType="application/octet-stream" />
<mimeMap fileExtension=".m4v" mimeType="application/octet-stream" />
<mimeMap fileExtension=".mp4" mimeType="application/octet-stream" />
<mimeMap fileExtension=".mp3" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>
如何添加.mp3
文件也要下载而不是播放?
我尝试了不同的事情,但是什么都没有起作用。对不起, https://en.wikipedia.org/wiki/regular_expression 不是我的Forte。
I have a dedicated folder that I use for when a .mp4
file needs downloading (instead of streaming inside a browser window).
This web.config file inside that folder manages to do this for me:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<outboundRules>
<remove name="Remove Server Response Header" />
<rule name="Remove Server Response Header" enabled="true">
<match serverVariable="RESPONSE_SERVER" pattern=".*" />
<conditions />
<action type="Rewrite" />
</rule>
<rule name="Force Download For MP4s" preCondition="FileIsMP4">
<match serverVariable="RESPONSE_Content-Disposition" pattern=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" matchType="Pattern" pattern="(.*)\\([^/]+)\.mp4quot; ignoreCase="true" negate="false" />
</conditions>
<action type="Rewrite" value="Value: attachment; filename={C:2}.mp4" />
</rule>
<preConditions>
<preCondition name="FileIsMP4">
<add input="{REQUEST_FILENAME}" pattern="\.mp4quot; />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<staticContent>
<remove fileExtension=".mp3" />
<remove fileExtension=".mp4" />
<remove fileExtension=".m4v" />
<remove fileExtension=".avi" />
<remove fileExtension=".mov" />
<mimeMap fileExtension=".mov" mimeType="application/octet-stream" />
<mimeMap fileExtension=".avi" mimeType="application/octet-stream" />
<mimeMap fileExtension=".m4v" mimeType="application/octet-stream" />
<mimeMap fileExtension=".mp4" mimeType="application/octet-stream" />
<mimeMap fileExtension=".mp3" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>
How would I go about adding .mp3
files to also download instead of playing?
I tried different things but nothing is working. Sorry, https://en.wikipedia.org/wiki/Regular_expression is not my forte.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
随着解决方法,我最终仅使用另一个文件夹用于.mp3文件。
As workaround I ended up just using another folder for .mp3 files.