【问题标题】:IIS HTTP Basic auth for specific URL特定 URL 的 IIS HTTP 基本身份验证
【发布时间】:2017-05-29 03:10:01
【问题描述】:

我想限制对特定路径使用 HTTP Basic Auth 的访问,以便访问 /www/private 的人会收到身份验证提示,但不会提示 /www/public 、 /www/public/dashboard ....

注意:“private”、“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 管理器中启用了基本身份验证和匿名授权

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

【问题讨论】:

  • 不太明白" 注意:"private"、"public"、"dashboard" 等不是文件夹,而是 url rewrite"。我没有看到任何重写为 private 的重写规则。你能提供你正在使用的网址吗?
  • 我正在使用 nette 框架来处理这个问题。对不起,我不知道具体情况。但关键是这些网址不是文件夹。

标签: iis basic-authentication


【解决方案1】:

IIS URLRewrite 模块在身份验证启动之前重写请求,因此根据您当前的重写规则,这是不可能的。

摘自here

URL 重写模块是插入到 Pre-begin Request 或 Begin Request 处的请求处理管道 阶段,然后使用一组评估请求的 URL 路径 重写规则。每个重写规则都会分析 URL 路径,如果所有 规则条件满足时,将原路径更改为新路径。 评估完所有规则后,URL 重写模块 生成最终 URL 路径,用于通过 IIS 管道处理的其余部分。这意味着处理程序 IIS 管道中的选择是基于重写的 URL 进行的 由 URL Rewrite 模块生成。

您的重写规则是这样一种方式,它将任何不是静态文件的路径重写为 index.php。 IIS 管道的其余部分将路径视为 index.php。您必须在 index.php 中实现您的身份验证。或者您可以轻松编写一个简单的 IIS 模块,SO question 谈论它。您必须添加更多逻辑来检查 URL(如果包含 www/private)并发送 401 等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-15
    • 1970-01-01
    • 2017-11-29
    • 2020-03-29
    • 1970-01-01
    • 2021-03-21
    • 2011-11-12
    相关资源
    最近更新 更多