2012-10-02 48 views
20

我正在爲我的公司構建一個簡單的內部應用程序,它需要Windows身份驗證以確保安全。所有其他認證模式都被禁用。我被困在Internet Explorer提示憑據3次的情況,然後失敗,出現此錯誤:IIS 7.5中的Windows身份驗證失敗

Not Authorized

HTTP Error 401. The requested resource requires user authentication.

然後我創建了一個最基本的網站測試了這一點。我在IIS中創建了一個新站點,將它放在自己的端口(:8111,隨機選擇)上,在其中放置一個靜態「default.htm」文件,禁用匿名身份驗證,然後啓用Windows身份驗證。其他一切都保留在默認設置下。端口號被分配,因爲我們在這臺機器上有多個站點共享相同的IP。

這裏有幾個方案:從Web服務器本身

  • 瀏覽,訪問http:// 本地主機:8111 /從另一臺計算機的工作原理 精細

  • 瀏覽,訪問http :// ServerIP地址:8111/ 正常工作

  • 從anot她的電腦,到http://服務器名:8111 /失敗 (要求憑據3次,然後給出了401錯誤)

我一直在網上進行搜索並嘗試找到沒有運氣的解決方案迄今。要麼我沒有找到它,要麼我對我讀的東西不夠了解。任何幫助將不勝感激。

回答

38

在與這個問題交戰2天后,剛剛在同事的幫助下找出瞭解決方案。他寫道:

There are 2 providers for Windows Authentication (Negotiate and NTLM). When setting the Website Authentication to Windows Authentication, while Windows Authentication is highlighted, click on the Providers link on the right pane or IIS Manager and move NTLM to the top. By default Negotiate is on top which is why you are getting an authentication prompt.

+1

+1這樣做對我來說,而更深入和正確的答案是要了解協商失敗的原因,這很快就會突出顯示錯誤。 – Seph

+0

因此而失去了半天。感謝您的修復。 – learnerplates

+0

這也解決了我。在我的情況下,我得到504網關超時錯誤。 –

17

錯誤401.1當您瀏覽使用集成身份驗證的網站時。

解決方案

禁用環回檢查

* In Registry Editor, locate and then click the following registry key: 

HKEY_LOCAL_MACHINE \系統\ CurrentControlSet \控制\ LSA

* Right-click Lsa, point to New, and then click DWORD Value. 
* Type DisableLoopbackCheck, and then press ENTER. 
* Right-click DisableLoopbackCheck, and then click Modify. 
* In the Value data box, type 1, and then click OK. 

http://support.microsoft.com/kb/896861

+0

謝謝!這對我來說很有效,我從過去幾個小時的開發人員痛苦和挫折中解脫出來。 –

+0

謝謝你。我只是瞥了一眼,看到了這個註冊表編輯。當上述NTLM修復程序不起作用時,我建議這是確定的下一步。只是驗證了我花費了很多工作時間來解決這個問題! – JTester

+0

這隻會影響Windows身份驗證從同一臺機器瀏覽網站託管在 – Mick

0

這已經有一段時間,因爲這個問題被問,但我知道很多人ru ñ進入它很多。這裏描述了更適當的修復方法:Kernel-mode authentication。我們在幾個月前實現了這一點,並且它工作正常。

另一個很好的解釋在這裏:MORE 2008 AND KERBEROS: AUTHENTICATION DENIED, APP POOL ACCOUNT BEING INGNORED

爲適用於單個站點:

cd %windir%\system32\inetsrv 
set SiteName=TheSiteName 
appcmd.exe set config "%SiteName%" -section:system.webServer/security/authentication/windowsAuthentication /useKernelMode:"True" /useAppPoolCredentials:"True" /commit:apphost 

或者適用於所有網站:

%windir%\system32\inetsrv\appcmd.exe set config -section:windowsAuthentication /useAppPoolCredentials:"True" /commit:apphost 
+0

嗯,我希望解釋爲什麼刪除協商神奇地修復它,但它不在這裏。我試圖解除內核模式,並將協商置回,並沒有解決它。刪除協商確實解決了它......但爲什麼? –

3

我個人建議不是全局禁用loopbackcheck在您的服務器上(IE:執行不是設置DisableLoopbackCheck的值爲1在您的註冊表中)。這是一個安全漏洞。請僅禁用已知主機。

這裏有一個Powershell功能讓你指出正確的方向。

function Add-LoopbackFix 
{ 
    param(
     [parameter(Mandatory=$true,position=0)] [string] $siteHostName 
    ) 

    $ErrorActionPreference = "Stop" 

    Write-Host "Adding loopback fix for $siteHostName" -NoNewLine 

    $str = Get-ItemProperty -Name "BackConnectionHostNames" -path 'HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0' -erroraction silentlycontinue 

    if ($str) { 
     if($($str.BackConnectionHostNames) -like "*$siteHostName*") 
     { 
      Write-Host "`tAlready in place" -f Cyan 
     } else{ 
      $str.BackConnectionHostNames += "`n$siteHostName" 
      Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0" -Name "BackConnectionHostNames" -Value $str.BackConnectionHostNames 
      Write-Host "`tDone" -f Green 
     } 
    } else { 
     New-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0" -Name "BackConnectionHostNames" -Value $siteHostName -PropertyType "MultiString" 
     Write-Host "`tDone" -f Green 
    } 

    Write-Host "`tnote: we are not disabling the loopback check all together, we are simply adding $siteHostName to an allowed list." -f DarkGray 
} 
> Add-LoopbackFix "ServerName" 

Source

+0

在內部開發服務器上禁用它應該沒有風險。如果它是一個生產服務器,您可能會遠程執行它,並且可能無論如何都會留下回環。 –

+0

@Ryios,即使在Dev中,推薦的方法是按域進行,而不是在全局進行。在生產中,我們有很多應用程序(SOA)在同一臺服務器上調用其他應用程序。 –

5

If it still does not work after moving NTML to top in the list of providers try to remove Negotiate completely so there is only NTML left.

問題解決了,我 - 移動NTML頂部沒有幫助的Windows Server 2012和IIS 8.5。我在下面的計算器問題中找到了解決方案:IIS 7.5 Windows Authentication Not Working in Chrome

+0

這對我有用。 – ben