【问题标题】:Exclude Path from windows authentication从 Windows 身份验证中排除路径
【发布时间】:2021-04-30 13:53:19
【问题描述】:

我在 Windows Server 2016 上有一个 IIS。 它作为我们的 Intranet 工作,并且启用了 Windows 身份验证以使用用户登录。 这一切都很完美。

现在我们确实想使用同一台服务器开发一个 api。因此,我需要从 Windows 身份验证中排除一条路径,并使其可用于匿名连接。 路径例如“[server]/api/”将由 PHP 处理,因此没有“物理”/api 文件夹。

我用在互联网上找到的以下部分编辑了 web.config

<location path="Default Web Site/api">
    <system.web>
     <authorization>
        <allow users="?"/>
     </authorization>
  </system.web>
</location>

我的第二次尝试是改变

<section name="anonymousAuthentication" overrideModeDefault="Deny" />

<section name="anonymousAuthentication" overrideModeDefault="Allow" />

在 applicationHost.config 中并将以下内容添加到 web.config

<location path="Path/To/Public/Folder">
    <system.webServer>
        <security>
            <authentication>
                <anonymousAuthentication enabled="true" />
            </authentication>
        </security>
    </system.webServer>
</location>

这两种尝试都不起作用,如果我打开 [server]/api,它仍然会要求我提供凭据。感谢任何帮助。


更新:我按照 MisterSmith 提供的链接,将 applicationHost.config Deny 编辑为 Allow

<section name="access" overrideModeDefault="Allow" />
<section name="anonymousAuthentication" overrideModeDefault="Allow" />
<section name="windowsAuthentication" overrideModeDefault="Allow" /> 

并在我的 web.config 中添加/替换了以下内容

<location path="api">
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
    <system.webServer> 
        <security>
            <authentication>
                <anonymousAuthentication enabled="true" />
            </authentication>
        </security>
    </system.webServer>
</location>

但我仍然收到 /api 的身份验证请求,我认为这是一个简单的错误,但我无法弄清楚我错过了什么.. 我有一个 64 位操作系统并使用了 64 位记事本++,但为了确保我尝试了推荐的 notepad2 和 notepad.exe 中的构建,但没有运气。 为了确保我对 web.config 的编辑没有导致错误,这里是全部

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpProtocol>
         <customHeaders>
           <add name="Access-Control-Allow-Origin" value="<server>" />
           <add name="Access-Control-Allow-Credentials" value="true" />        
         </customHeaders>
       </httpProtocol>
        <rewrite>
            <rules>
                <rule name="Importierte Regel 1" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <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/{R:1}" />
                </rule>
            </rules>
        </rewrite>
        <httpErrors errorMode="Detailed" />
        <security>
            <authentication>
                <anonymousAuthentication enabled="false" />
            </authentication>
        </security>
    </system.webServer>
    <location path="api">
        <system.web>
            <authorization>
                <allow users="*" />
            </authorization>
        </system.web>
        <system.webServer> 
            <security>
                <authentication>
                    <anonymousAuthentication enabled="true" />
                </authentication>
            </security>
        </system.webServer>
    </location>

【问题讨论】:

标签: iis windows-authentication


【解决方案1】:

您已关闭,但您的位置块和应用程序主机缺少一些位 - 请参阅帖子 IIS 8.5: Change authentification mode for url sub path。此外,如果您遇到奇怪的行为,请注意有关文本编辑器的 32/64 位“位”的 cmets - 如果您使用 32 位编辑器,Windows 将为您提供 32 位应用程序主机文件,使用 64 位编辑器窗口返回 64 位应用程序主机文件(如果怀疑常规内置 notepad.exe 在 64 位 Windows 上始终是 64 位应用程序)。

【讨论】:

  • 嘿,谢谢,但我无法让它工作,我已经用更多信息更新了我的问题
  • 尝试在您的位置块中的&lt;anonymousAuthentication enabled="true" /&gt; 之前添加&lt;windowsAuthentication enabled="false" /&gt;
  • 仍然不起作用..我感觉错误在其他地方,而不是在 web.config 或 applicationHost.config 中:/
  • 您是否尝试过在 api 位置块内显式禁用 Windows 身份验证以及启用匿名身份验证? Windows auth 可能在处理程序列表中的匿名之前/如果您可能需要使用虚拟目录或使用 ARR 模块作为反向代理来隔离您的 /api 应用程序,则失败。你能扩展你的主要应用程序/api的设置方式吗?
【解决方案2】:

在史密斯先生的帮助下找到了它 “错误”是我的位置错误。因为我的路线一般不存在于物理上,而是仅在 php 脚本中处理,所以我在 web.config 中有重写规则 这导致&lt;server&gt;/test 被重写为&lt;server&gt;/index.php/test

考虑到这一点,需要将位置块中的路径从&lt;location path="api"&gt; 更改为&lt;location path="index.php/api"&gt;,这解决了问题!

【讨论】:

    猜你喜欢
    • 2016-05-10
    • 1970-01-01
    • 1970-01-01
    • 2020-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多