如何在 Windows Server 2019 上限制用户代理对文件夹的访问?

How to restrict access to folder by user-agent on Windows Server 2019?

我有一个在几个不同网站的网页上运行的解决方案,它使用存储在 Windows Server 2019 上的 JS 文件,就像使用 CDN 一样。 JS 文件只能由一个特定的 Web 浏览器使用,例如“Firefox”,并且只有该浏览器应该使用这些文件。所以我想知道我们是否可以将服务器配置为只允许该浏览器访问 JS 文件夹。这可能吗?如何实现?

在 IIS 管理器中,您可以使用 UrlRewrite 在 web.config...

中设置重定向
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Non-Firefox Redirect" stopProcessing="true">
                    <match url="^foldername/.*$" />
                    <conditions>
                        <add input="{HTTP_USER_AGENT}" pattern="Firefox" negate="true" />
                    </conditions>
                    <action type="Redirect" url="https://example.com/somepage.html" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
        </system.webServer>
</configuration>