【问题标题】:ASP.NET MVC, Windows Authentication and load balancer probesASP.NET MVC、Windows 身份验证和负载平衡器探测
【发布时间】:2014-11-14 12:59:14
【问题描述】:

我有一个在 IIS 8 和 Windows Server 2012 上运行的带有 Windows 集成身份验证的 ASP.NET MVC 应用程序。此应用程序部署在两个服务器上,它们位于负载平衡器后面。负载平衡器正在探测两个应用程序服务器以确定它们是否正在运行 - 它尝试下载名为 IsAlive.html 的静态 html 页面。如果负载均衡器成功下载了 HTTP 状态为 200 OK 的页面,则认为服务器正在运行。

问题是,负载平衡器的请求无法使用 Windows 集成身份验证进行身份验证。所以我尝试让网页 IsAlive.html 无需任何形式的身份验证即可公开使用。

这就是 web.config 的样子。 IsAlive 页面位于 Web 应用的根目录中。

<system.web>
    <httpRuntime targetFramework="4.5" />
    <compilation debug="true" targetFramework="4.5" />
    <authentication mode="Windows" />        
</system.web>

<!-- IsAlive.html static page is used by a load balancer for server fault detection. It requires anonymous authentication. -->
<location path="IsAlive.html">
  <system.web>
    <authorization>
      <allow users="*"/>
    </authorization>
  </system.web>
</location>

这不起作用,直到我在 IIS 中打开匿名身份验证(在应用程序的虚拟目录范围内):

但是这种方法有一个问题:

1) 负载均衡器现在会在尝试下载 IsAlive.html 页面时随机收到 401 Unauthorized 响应。有时它与 200 OK 一起工作,有时它不是。我在 IIS 日志中没有看到 401 响应。负载平衡器管理员向我报告了此问题(我无权访问此设备)。

2) 在这个页面上:http://technet.microsoft.com/en-us/library/jj635855.aspx我找到了可能的原因:

请注意,为同一网站配置匿名身份验证和其他身份验证类型可能会导致身份验证问题。

如果您配置匿名身份验证和其他身份验证类型,则结果由模块运行的顺序决定。例如,如果同时配置了匿名身份验证和 Windows 身份验证,并且首先运行匿名身份验证,则永远不会运行 Windows 身份验证。

我的问题是:如何正确地使 IsAlive.html 页面无需任何形式的身份验证即可访问负载均衡器探测,同时在 Windows 集成身份验证下拥有 ASP:NET MVC 应用程序的其余部分?

谢谢你, 迈克尔

【问题讨论】:

    标签: .net asp.net-mvc iis windows-authentication iis-8


    【解决方案1】:

    我找到了解决办法:

    1. 像这样设置您的网站配置文件:

      <?xml version="1.0" encoding="UTF-8"?>
      <configuration>
          <!--for whole site, disable anonymous authentication and enable windows authentication-->
          <system.webServer>
              <security>
                <authentication>
                      <windowsAuthentication enabled="true" />
                      <anonymousAuthentication enabled="false" />
                </authentication>
              </security>
        </system.webServer>
        <!--for specific page, disable windows and enable anonymous authentication-->
        <location path="IsAlive.html">
              <system.webServer>
                <security>
                      <authentication>
                        <windowsAuthentication enabled="false" />
                        <anonymousAuthentication enabled="true" />
                      </authentication>
                </security>
              </system.webServer>
        </location>
      </configuration>
      
    2. 为了能够更改子文件夹中的身份验证,必须在服务器级别的 applicationHost.config 中将 IIS 设置为允许它。为此,请执行以下步骤:

      1. 打开 IIS 管理器
      2. 在“连接”窗格中选择服务器
      3. 在主窗格中打开配置编辑器
      4. 在顶部的“部分”下拉列表中,选择要解锁的部分 system.webServer/security/authentication/anonymousAuthentication
      5. 单击右侧窗格中的解锁属性
      6. 对 system.webServer/security/authentication/windowsAuthentication 部分重复
      7. 重新启动 IIS(可选)- 在“连接”窗格中选择服务器,单击“操作”窗格中的重新启动

    我能够使用 Fiddler 验证正确的行为:

    【讨论】:

      【解决方案2】:

      您可以将 IsAlive.html 部署在该网站下同一应用程序池中的虚拟目录(应用程序)中,并为该应用程序关闭 Windows 身份验证。

      【讨论】:

        【解决方案3】:

        您可以直接将页面添加到iis服务器,不需要单独的页面进行错误处理,进入iis并点击默认站点,您将在iis上看到错误选项卡,更改页面给你的

        【讨论】:

        • 对不起,这不是我的问题的答案。
        猜你喜欢
        • 1970-01-01
        • 2010-12-15
        • 2021-06-06
        • 1970-01-01
        • 1970-01-01
        • 2023-04-04
        • 1970-01-01
        • 2020-01-18
        • 2018-07-06
        相关资源
        最近更新 更多