【发布时间】: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 身份验证。您是否尝试在 IIS 中设置匿名身份验证并禁用 Windows 身份验证。这里是文档:docs.microsoft.com/en-us/iis/configuration/system.webserver/…
标签: iis windows-authentication