从windows身份验证中排除路径



我在Windows Server 2016上有一个IIS。它就像我们的内联网一样工作,并且为使用用户登录启用了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.configDeny编辑为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 8.5:更改url子路径的身份验证模式。此外,如果你有奇怪的行为,请注意关于32/64bit的评论;bitness";如果您使用32位编辑器,Windows将为您提供32位applicationHost文件,使用64位编辑器,Windows将返回64位applicationHost(如果有疑问,常规内置notepad.exe在64位Windows上始终是64位应用程序(。

在MisterSmith的帮助下找到了它"错误"是我的位置不对。因为我的路由通常不存在,而是只在php脚本中处理,所以我在web.config中有重写规则这导致<server>/test被重写为<server>/index.php/test

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

最新更新