特定URL的IIS HTTP基本身份验证

特定URL的IIS HTTP基本身份验证,iis,basic-authentication,Iis,Basic Authentication,我想使用HTTP Basic Auth限制对特定路径的访问,这样访问/www/private的人将得到验证提示,而不是/www/public、/www/public/dashboard、 注意:“私有”、“公共”、“仪表板”等不是文件夹,而是url重写 我当前的网络配置: <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite>

我想使用HTTP Basic Auth限制对特定路径的访问,这样访问/www/private的人将得到验证提示,而不是/www/public、/www/public/dashboard、

注意:“私有”、“公共”、“仪表板”等不是文件夹,而是url重写

我当前的网络配置:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="Imported Rule 1" stopProcessing="true">
                <match url="\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz)$" ignoreCase="false" negate="true" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                </conditions>
                <action type="Rewrite" url="index.php" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>
<location path="mysite/www/private">
    <system.webServer>
        <security>
            <authentication>
                <anonymousAuthentication enabled="false" />
                <basicAuthentication enabled="true" />
                <windowsAuthentication enabled="false" />
            </authentication>
        </security>
    </system.webServer>
</location>
<location path="mysite/www">
    <system.webServer>
        <security>
            <authentication>
                <anonymousAuthentication enabled="true" />
                <basicAuthentication enabled="false" />
                <windowsAuthentication enabled="false" />
            </authentication>
        </security>
    </system.webServer>
</location>


但是,这不起作用-它从不提示授权

IIS URLRewite模块在身份验证开始之前重写请求,因此使用当前的重写规则,这是不可能的

超出

URL重写模块是插入到 预开始请求或开始请求处的请求处理管道 阶段,然后使用一组 重写规则。每个重写规则分析URL路径,如果所有 满足规则条件后,将原始路径更改为新路径。 对所有规则求值后,URL重写模块 生成最终URL路径,该路径用于通过 IIS管道处理的其余部分。这意味着处理程序 IIS管道中的选择是基于 由URL重写模块生成


您的重写规则将任何不指向静态文件的路径重写为index.php。IIS管道的其余部分将路径视为index.php。您必须在index.php中实现身份验证,或者您可以轻松地编写一个简单的IIS模块,本文将介绍这一点。你必须添加更多的逻辑来检查URL(如果包含www/private)和发送401等。

不太理解“注意:“private”、“public”、“dashboard”等不是文件夹,而是URL重写。我没有看到任何重写规则重写为private。你能给出你正在使用的URL吗?我使用的是nette框架,谁来处理这件事。对不起,我不知道具体情况。但关键是这些URL不是文件夹。