如何在 IIS 中强制下载 .mp3 和 .mp4 文件

发布于 2025-01-21 02:49:22 字数 2557 浏览 0 评论 0原文

我有一个专用文件夹,当.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="(.*)\\([^/]+)\.mp4
quot; 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
quot; />
                    </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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除→记忆 2025-01-28 02:49:22

随着解决方法,我最终仅使用另一个文件夹用于.mp3文件。

As workaround I ended up just using another folder for .mp3 files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文