IIS 8.5:更改 url 子路径的身份验证模式

IIS 8.5: Change authentification mode for url sub path

我们有一个客户端 Intranet Web 应用程序 运行ning 作为 IIS 8.5 上的远程代理,启用了 Windows 身份验证。现在,我们需要在 URL 子路径 /api/ 上禁用 Windows 身份验证 并启用 匿名身份验证使来自此路径的所有数据在客户端 Intranet 域内公开可用。

实际上,来自 chensformers (Add authentication to subfolders without creating a web application) 的解决方案听起来很有前途。但是还没有达到 运行,因为我缺少 部分声明

如何配置 IIS 8.5 来实现这一点?

首先,您需要将 api 文件夹转换为应用程序,即 右键单击该文件夹 => 转换为应用程序 .在中央窗格中将其转换为应用程序后,双击 Authentication => Select Anonymous Authentication 并启用它。禁用所有其他身份验证模式。

P.S。 - 您可以尝试不转换为应用程序。我还没有测试过,所以不确定它是否可以作为文件夹使用。

经过长时间的尝试,我自己找到了答案。答案分为两部分:

  1. @Tim Lewis (Allow anonymous authentication for a single folder in web.config?) 的回答让我找到了正确的配置。在 C:\Windows\System32\inetsrv\config 中的文件 applicationHost.config 中,我将以下行从 Deny 更改为 Allow

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

    然后在 C:\inetpub\wwwrootweb.config 中,我在最后一个 </configuration> 标签之前插入了以下行:

    <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 身份验证应该被子路径覆盖(/api 在我的例子中) 并且子路径中的每个 URL 都应该公开可用。

  2. 但是,如果这个配置一开始不起作用,可能是您选择的编辑器(在我的例子中是 Notepad++)没有打开appplictionHost.config 的正确内容(无论出于何种原因)以及其中的所有更改根本不会生效(另请参阅@MeanGreen )。

    我通过安装和使用 Notepad2 x64 (http://www.flos-freeware.ch/notepad2.html) 解决了这个问题。在此之后,上述更改立即生效。

PS:另请参阅 http://forums.iis.net/t/1233382.aspx?IIS+8+5+Change+authentification+mode+for+url+sub+path 以获取有关此主题的更详细讨论。

对于未来的 google 员工。

这个 Question/Answer 帮了我大忙!我也在使用虚拟路径,除了它来自 python flask 应用程序。除了我有一个我想要在 windowsauthentication 后面的管理网站,该网站的其余部分是 anonymousAuthentication .

对我来说这很有效:

  1. 允许委派 windows 和匿名身份验证模块遵循此答案:

  2. 正在更新 web.config

<configuration>
    <!-- ...the beginning of the web.config file as is... -->
    </appSettings>
    <location path="admin">  <!-- relative to where the web.config file is located -->
      <system.web>
        <authorization>
          <allow users="*" />
        </authorization>
      </system.web>
      <system.webServer>
        <security>
          <authentication>
            <windowsAuthentication enabled="true" />
            <anonymousAuthentication enabled="false" />
          </authentication>
        </security>
      </system.webServer>
    </location>
</configuration>

我不必重新启动 IIS 管理器或服务器。