2014-11-14 80 views
0

我有一個運行在IIS 8和Windows Server 2012上的Windows集成身份驗證的ASP.NET MVC應用程序。此應用程序部署在位於負載均衡器後面的兩臺服務器上。負載平衡器正在探測兩個應用服務器,以確定它們是否正在運行 - 它嘗試下載一個名爲IsAlive.html的靜態html頁面。如果負載平衡器成功下載HTTP狀態爲200 OK的頁面,則認爲該服務器正在運行。ASP.NET MVC,Windows身份驗證和負載平衡器探針

問題是,負載平衡器的請求無法使用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中啓用匿名身份驗證(對應用程序的虛擬目錄的範圍):

IIS anonymous authentication

但這種方法有一個問題:

1 )當負載均衡器嘗試下載IsAlive.html頁面時,它會隨機接收401個未經授權的響應。某些時候它使用200 OK,但有時它不是。我在IIS日誌中看不到401響應。負載平衡器管理員向我報告了這個問題(我無權訪問此設備)。

2)在此頁面:http://technet.microsoft.com/en-us/library/jj635855.aspx我發現可能的原因:

注意,與同一網站的另一個身份驗證類型一起配置匿名身份驗證可能會導致身份驗證問題。

如果您配置匿名身份驗證和另一種身份驗證類型,則結果取決於模塊的運行順序。例如,如果配置了匿名身份驗證和Windows身份驗證,並且首先運行匿名身份驗證,則Windows身份驗證永遠不會運行。

我的問題是:如何正確地使可用IsAlive.html頁沒有任何形式的認證,以負載均衡器探頭,並在同一時間有ASP的休息:NET MVC應用程序在Windows集成身份驗證?

謝謝 米哈爾

回答

2

頁我找到了解決辦法:

  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. 要在子FO能夠改變身份驗證lders,必須將IIS設置爲在服務器級別的applicationHost.config中允許它。要做到這一點,請執行下列步驟操作:

    1. 打開IIS管理器
    2. 選擇連接窗格
    3. 打開配置編輯器主窗格
    4. 在第下拉頂部的服務器,請選擇system.webServer/security/authentication/anonymousAuthentication
    5. 單擊右窗格中的解除鎖定屬性
    6. 對system.webServer/security/authentication/windowsAuthentication部分重複執行
    7. 重新啓動IIS(可選) - 選擇連接窗格中的服務器,單擊重新啓動在操作窗格中

我能夠驗證正確的行爲與小提琴手:

fiddler

0

你可以在該網站在相同的應用程序池的虛擬目錄(應用程序)部署IsAlive.html並打開Windows驗證關閉該應用程序。

0

您可以直接將頁面添加到iis服務器,您不需要爲錯誤處理製作單獨的頁面,轉到iis並單擊默認網站,您將看到iis上的錯誤標籤,更改您的

+0

很抱歉,這不是我的問題的答案。 – Mikee 2014-11-15 16:41:54