2013-07-04 4 views
32

Ich hatte vor kurzem ein unangenehmes Problem, die Windows-Authentifizierung auf einer lokalen Instanz von IIS 7.5 (Windows 7 Pro) auf einer ASP.net 4.0-Site arbeiten zu lassen. Ich folgte den grundlegenden Schritten.Windows-Authentifizierung funktioniert nicht auf dem lokalen IIS 7.5. Fehler 401.1

IIS-Authentifizierung

  • Disable Anonyme Authentifizierung
  • Aktivieren Sie die Windows-Authentifizierung

bearbeiten web.config

<authentication mode="Windows" /> 

Dieses eine schöne Aufgabe hat die Windows-Authentifizierung zu ermöglichen, aber jeden Versuch Login wurde abgelehnt und letztlich zurückgegeben 401.1 Fehler. Hier begann das Problem. Es gibt viele Gründe dafür, die im Internet gut dokumentiert sind, einschließlich hier auf Stack Overflow.

Ich hatte versucht:

  • Bearbeiten von IIS-Authentifizierung ‚Erweiterte Einstellungen‘ für Windows-Authentifizierung
  • Bearbeiten ‚Providers‘ NTLM oben Verhandeln zu bewegen, um IIS-Authentifizierung Erweiterter Schutz und Kernelmodus-Authentifizierung zu deaktivieren.
  • Bearbeiten von IIS .NET-Autorisierungsregeln zur expliziten Erlauben von Benutzern (und verschiedenen anderen Kombinationen).
  • Verschiedene IIS-Befehlszeilenskripts und Tweaks.
  • Verschiedene Konfigurationsänderungen in der Datei web.config.
  • Sogar einige Dateisystem-Berechtigungen optimieren.

Aber alles ohne Erfolg blieb die gefürchtete 401.1.

Dies ist wirklich ein Fall von "kann das Holz für die Bäume nicht sehen". Keine der Lösungen, die ich finden konnte (nennen Sie es einen Fall von schlechten Suchparametern, wenn Sie wollen), arbeitete für mich, also dachte ich, dass es sich lohnt, diese Frage zu veröffentlichen, um hoffentlich eine klare Antwort zu geben, die leichter für jemanden zu finden ist, der das gleiche Problem hat .

Antwort

62

Das Problem hier ist, dass moderne Windows-Versionen (Windows XP SP2, Windows Server 2003 SP1 und höher) eine Loopback-Check-Sicherheitsfunktion enthalten, die Reflektionsangriffe auf Ihren Computer verhindern soll. Daher schlägt die Authentifizierung fehl, wenn der FQDN oder der benutzerdefinierte Hostheader, den Sie verwenden, nicht mit dem lokalen Computernamen übereinstimmt.

Dies kann durch explizite Angabe von Hostnamen oder durch Deaktivieren der Loopback-Prüfung gelöst werden. Offensichtlich ist ersteres der kontrolliertere Ansatz.

  1. Stellen Sie den DisableStrictNameChecking Registrierungseintrag auf 1. Siehe: 281308(Anmerkung: Ich nicht, dies zu tun haben müssen)
  2. Im Registrierungs-Editor, und klicken Sie dann auf den folgenden Registrierungsschlüssel: HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Lsa \ MSV1_0
  3. Klicken Sie mit der rechten Maustaste auf MSV1_0, zeigen Sie auf Neu, und klicken Sie dann auf Multi-String Value.
  4. Geben Sie BackConnectionHostNames ein, und drücken Sie dann die EINGABETASTE.
  5. Klicken Sie mit der rechten Maustaste auf BackConnectionHostNames, und klicken Sie dann auf Ändern.
  6. Geben Sie in das Feld Wert den Hostnamen oder die Hostnamen für die Sites ein, die sich auf dem lokalen Computer befinden, und klicken Sie dann auf OK.
  7. Beenden Sie den Registrierungseditor, und starten Sie den IISAdmin-Dienst neu.

Ausführliche Informationen, wie man dies tun kann, auf MSDN finden: 896861

Hope this jemand heraus hilft. Wenn Sie alternative Vorschläge oder Verbesserungen haben, fügen Sie bitte hinzu.

+1

In meinem Fall war es so einfach wie mit http: // localhost/anstelle von http://foobar.com/ Adresse. Danke, dass Sie mich in diese Richtung weisen. –

+1

Leider hat das auch nicht für mich funktioniert. Mein Problem ist, dass das modale Login-Fenster weiterhin angezeigt wird. – joey

+1

Ich konnte umgehen, indem ich eine Bindung in IIS hinzufügte und Hostname als meinen Computernamen verwendete. Das hat es für mich gelöst. – joey

1

Installieren Sie Ihre IIS-Funktionen erneut und stellen Sie sicher, dass die WINDOWS-Kontrollkästchen aktiviert sind.

3

Ich möchte Michael Darks Kommentar als Antwort hinzufügen, weil ich keine Berechtigung habe, meine Registrierung zu ändern, so dass Pete's Antwort nicht für mich funktioniert, aber ich konnte das Problem lösen.

Ich löste es durch Hinzufügen einer neuen Bindung zu meiner Website ohne angegebenen Host-Namen und einem anderen Port (weil localhost: 80 für mich verwendet wird). Sobald ich versuchte, es von http://localhost:86/mypage anzurufen, funktionierte es. Nach einer kurzen Überprüfung im Browser habe ich einige Male mit cURL getestet und meine Zugangsdaten korrekt akzeptiert und abgelehnt.

+0

Das funktionierte auch für mich. Ich habe nicht einmal daran gedacht, die Host-Bindung zu ändern, aber als ich es getan habe, hat es sofort funktioniert. Irgendwelche Ideen, was das verursacht? – smoksnes

+0

Frage nicht weiter oben. Ich habe die Lösung von PeteWifi ausprobiert und es funktioniert auch sehr gut. – smoksnes

1

Hier ist der PowerShell-Code, den ich verwende, um Host-Namen zurück zu verbinden und IIS zu behandeln. Beachten Sie, dass die Commandlets mit ein wenig Arbeit in einem Modul gespeichert und auf diese Weise verwendet werden können.

Import-Module WebAdministration 

function Add-BackConnectionHostname 
{ 
    <# 
    .SYNOPSIS 
    Adds the back connection hostnames that will bypass the server loopback check. 
    .DESCRIPTION 
    Adds the hostname to the list of back connection hostnames that will bypass the server loopback check. Back connection host names 
    can be used to address the problem with IIS sites using Windows Authentication that is described in Microsoft KB896861. 
    .EXAMPLE 
    Add-BackConnectionHostname mywebsite.mydomain.tld 
    .EXAMPLE 
    Add-BackConnectionHostname mywebsite1.mydomain.tld, mywebsite2.mydomain.tld 
    .PARAMETER Hostname 
    The Hostname to add to the back connection hostnames list. 
    .LINK 
    Remove-BackConnectionHostname 
    Get-BackConnectionHostname 
    Enable-ServerLoopbackCheck 
    Disable-ServerLoopbackCheck 
    Get-ServerLoopbackCheck 
    "You receive error 401.1 when you browse a Web site that uses Integrated Authentication and is hosted on IIS 5.1 or a later version" (http://support.microsoft.com/en-us/kb/896861) 
    #> 
    [CmdletBinding(SupportsShouldProcess = $true)] 
    param 
    (
     [Parameter(ValueFromPipeline = $true, Mandatory = $true)] 
     [string] $Hostname 
    ) 

    begin 
    { 
     $keyPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0" 
     $propertyName = "BackConnectionHostnames" 
     $key = Get-Item $keyPath 
     $property = $null 
     $propertyValues = $null 

     if ($key -ne $null) 
     { 
      $property = Get-ItemProperty $keyPath -Name $propertyName -ErrorAction SilentlyContinue 

      if ($property -eq $null) 
      { 
       $property = New-ItemProperty $keyPath -Name $propertyName -Value $null -PropertyType ([Microsoft.Win32.RegistryValueKind]::MultiString) -ErrorAction Stop 

       Write-Verbose "Created the $($propertyName) property." 
      } 

      if ($property -ne $null) 
      { 
       $propertyValues = $property.$propertyName 
      } 
     } 
    } 

    process 
    { 
     if ($property -ne $null) 
     { 
      foreach ($hostNameValue in $Hostname) 
      { 
       if ([string]::IsNullOrWhiteSpace($hostName) -eq $false -and $propertyValues -notcontains $hostNameValue) 
       { 
        $propertyValues += $hostNameValue 

        Write-Verbose "Added $($hostName) to the back connection hostnames." 
       } 
       else 
       { 
        Write-Verbose "Back connection host names already has an entry for $($hostName)." 
       } 
      } 
     } 
    } 

    end 
    { 
     if ($propertyValues -ne $null) 
     { 
      $propertyValues = $propertyValues | ?{ [string]::IsNullOrWhiteSpace($_) -eq $false } | Sort -Unique 
      Set-ItemProperty $keyPath -Name $propertyName -Value $propertyValues 
     } 
    } 
} 

function Remove-BackConnectionHostname 
{ 
    <# 
    .SYNOPSIS 
    Removes the hostname from the list of back connection hostnames that will bypass the server loopback check. 
    .DESCRIPTION 
    Removes the hostname from the list of back connection hostnames that will bypass the server loopback check. 
    .EXAMPLE 
    Remove-BackConnectionHostname mywebsite.mydomain.tld 
    .EXAMPLE 
    Remove-BackConnectionHostname mywebsite1.mydomain.tld, mywebsite2.mydomain.tld 
    .PARAMETER Hostname 
    The Hostname to remove from the back connection hostnames list. 
    .LINK 
    Add-BackConnectionHostname 
    Get-BackConnectionHostname 
    Enable-ServerLoopbackCheck 
    Disable-ServerLoopbackCheck 
    Get-ServerLoopbackCheck 
    "You receive error 401.1 when you browse a Web site that uses Integrated Authentication and is hosted on IIS 5.1 or a later version" (http://support.microsoft.com/en-us/kb/896861) 
    #> 
    [CmdletBinding(SupportsShouldProcess = $true)] 
    param 
    (
     [Parameter(ValueFromPipeline = $true, Mandatory = $true)] 
     [string] $Hostname 
    ) 

    begin 
    { 
     $keyPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0" 
     $propertyName = "BackConnectionHostnames" 
     $key = Get-Item $keyPath 
     $property = $null 
     $propertyValues = $null 

     if ($key -ne $null) 
     { 
      $property = Get-ItemProperty $keyPath -Name $propertyName -ErrorAction SilentlyContinue 

      if ($property -ne $null) 
      { 
       $propertyValues = $property.$propertyName 
      } 
      else 
      { 
       Write-Verbose "The $($propertyName) property was not found." 
      } 
     } 
    } 

    process 
    { 
     if ($property -ne $null) 
     { 
      foreach ($hostNameValue in $Hostname) 
      { 
       if ($propertyValues -contains $hostNameValue) 
       { 
        $propertyValues = $propertyValues | ? { $_ -ne $hostName } 

        Write-Verbose "Removed $($hostName) from the $($propertyName) property." 
       } 
       else 
       { 
        Write-Verbose "No entry for $($hostName) was found in the $($propertyName) property." 
       } 
      } 
     } 
    } 

    end 
    { 
     if ($property -ne $null) 
     { 
      $propertyValues = $propertyValues | ?{ [string]::IsNullOrWhiteSpace($_) -eq $false } | Sort -Unique 

      if ($propertyValues.Length -ne 0) 
      { 
       Set-ItemProperty $keyPath -Name $propertyName -Value $propertyValues 
      } 
      else 
      { 
       Remove-ItemProperty $keyPath -Name $propertyName 

       Write-Verbose "No entries remain after removing $($hostName). The $($propertyName) property was removed." 
      } 
     } 
    } 
} 

function Get-BackConnectionHostname 
{ 
    <# 
    .SYNOPSIS 
    Gets the list of back connection hostnames that will bypass the server loopback check. 
    .DESCRIPTION 
    Gets the back connection hostnames that will bypass the server loopback check. Back connection host names can be used to address 
    the problem with IIS sites using Windows Authentication that is described in Microsoft KB896861. 
    .EXAMPLE 
    Get-BackConnectionHostname 
    .LINK 
    Add-BackConnectionHostname 
    Remove-BackConnectionHostname 
    Enable-ServerLoopbackCheck 
    Disable-ServerLoopbackCheck 
    Get-ServerLoopbackCheck 
    "You receive error 401.1 when you browse a Web site that uses Integrated Authentication and is hosted on IIS 5.1 or a later version" (http://support.microsoft.com/en-us/kb/896861) 
    #> 
    [CmdletBinding(SupportsShouldProcess = $false)] 
    param 
    (
    ) 

    begin 
    { 
     $keyPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0" 
     $propertyName = "BackConnectionHostnames" 
     $key = Get-Item $keyPath 
     $property = $null 

     if ($key -ne $null) 
     { 
      $property = Get-ItemProperty $keyPath -Name $propertyName -ErrorAction SilentlyContinue 

      if ($property -eq $null) 
      { 
       Write-Verbose "The $($propertyName) property was not found." 
      } 
     } 
    } 

    process 
    { 
     $propertyValues = $null 

     if ($property -ne $null) 
     { 
      $propertyValues = $property.$propertyName 
     } 

     return $propertyValues 
    } 

    end 
    { 
    } 
} 

function Enable-ServerLoopbackCheck 
{ 
    <# 
    .SYNOPSIS 
    Enables the server loopback check. Enabled is the normal state for a Windows Server. 
    .DESCRIPTION 
    Enables the server loopback check. Having the loopback check enabled is the normal state for a Windows Server. Disabling the loopback check can be used to address 
    the problem with IIS sites using Windows Authentication that is described in Microsoft KB896861. It is NOT the preferred method. See the KB article for more details. 
    .EXAMPLE 
    Enable-ServerLoopbackCheck 
    .LINK 
    Add-BackConnectionHostname 
    Remove-BackConnectionHostname 
    Get-BackConnectionHostname 
    Enable-ServerLoopbackCheck 
    Get-ServerLoopbackCheck 
    "You receive error 401.1 when you browse a Web site that uses Integrated Authentication and is hosted on IIS 5.1 or a later version" (http://support.microsoft.com/en-us/kb/896861) 
    #> 
    [CmdletBinding(SupportsShouldProcess = $true)] 
    param 
    (
    ) 

    begin 
    { 
     $keyPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" 
     $propertyName = "DisableLoopbackCheck" 
     $key = Get-Item $keyPath 
     $property = $null 

     if ($key -ne $null) 
     { 
      $property = Get-ItemProperty $keyPath -Name $propertyName -ErrorAction SilentlyContinue 

      if ($property -eq $null) 
      { 
       Write-Verbose "The $($propertyName) property was not found." 
      } 
     } 
    } 

    process 
    { 
     if ($property -ne $null) 
     { 
      Set-ItemProperty $keyPath -Name $propertyName -Value 0 
     } 
    } 

    end 
    { 
    } 
} 

function Disable-ServerLoopbackCheck 
{ 
    <# 
    .SYNOPSIS 
    Disables the server loopback check for all hostnames. Enabled is the normal state for a Windows Server. 
    .DESCRIPTION 
    Disables the server loopback check for all hostnames. Having the loopback check enabled is the normal state for a Windows Server. Disabling the loopback check can be used 
    to address the problem with IIS sites using Windows Authentication that is described in Microsoft KB896861. It is NOT the preferred method. See the KB article for more details. 
    .EXAMPLE 
    Disable-ServerLoopbackCheck 
    .LINK 
    Add-BackConnectionHostname 
    Remove-BackConnectionHostname 
    Get-BackConnectionHostname 
    Enable-ServerLoopbackCheck 
    Get-ServerLoopbackCheck 
    "You receive error 401.1 when you browse a Web site that uses Integrated Authentication and is hosted on IIS 5.1 or a later version" (http://support.microsoft.com/en-us/kb/896861) 
    #> 
    [CmdletBinding(SupportsShouldProcess = $true)] 
    param 
    (
    ) 

    begin 
    { 
     $keyPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" 
     $propertyName = "DisableLoopbackCheck" 
     $key = Get-Item $keyPath 
     $property = $null 

     if ($key -ne $null) 
     { 
      $property = Get-ItemProperty $keyPath -Name $propertyName -ErrorAction SilentlyContinue 

      if ($property -eq $null) 
      { 
       Write-Verbose "The $($propertyName) property was not found." 
      } 
     } 
    } 

    process 
    { 
     if ($property -ne $null) 
     { 
      Set-ItemProperty $keyPath -Name $propertyName -Value 1 
     } 
     else 
     { 
      $property = New-ItemProperty $keyPath -Name $propertyName -PropertyType ([Microsoft.Win32.RegistryValueKind]::DWord) -Value 1 
     } 
    } 

    end 
    { 
    } 
} 

function Get-ServerLoopbackCheck 
{ 
    <# 
    .SYNOPSIS 
    Gets the status of the server loopback check. Enabled is the normal state for a Windows Server. 
    .DESCRIPTION 
    Gets the status of the server loopback check. Having the loopback check enabled is the normal state for a Windows Server. Disabling the loopback check can be used 
    to address the problem with IIS sites using Windows Authentication that is described in Microsoft KB896861. It is NOT the preferred method. See the KB article for 
    more details. 
    .EXAMPLE 
    Get-ServerLoopbackCheck 
    .LINK 
    Add-BackConnectionHostname 
    Remove-BackConnectionHostname 
    Get-BackConnectionHostname 
    Enable-ServerLoopbackCheck 
    Disable-ServerLoopbackCheck 
    "You receive error 401.1 when you browse a Web site that uses Integrated Authentication and is hosted on IIS 5.1 or a later version" (http://support.microsoft.com/en-us/kb/896861) 
    #> 
    [CmdletBinding(SupportsShouldProcess = $false)] 
    param 
    (
    ) 

    begin 
    { 
     $keyPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" 
     $propertyName = "DisableLoopbackCheck" 
     $key = Get-Item $keyPath 
     $property = $null 

     if ($key -ne $null) 
     { 
      $property = Get-ItemProperty $keyPath -Name $propertyName -ErrorAction SilentlyContinue 
     } 
    } 

    process 
    { 
     $loopbackCheckStatus = "Enabled" 

     if ($property -ne $null) 
     { 
      switch ($property) 
      { 
       0 { $loopbackCheckStatus = "Enabled" } 
       1 { $loopbackCheckStatus = "Disabled" } 
       default { $loopbackCheckStatus = "Unknown" } 
      } 
     } 

     return $loopbackCheckStatus 
    } 

    end 
    { 
    } 
} 

function Get-WebsiteHostname 
{ 
    <# 
    .SYNOPSIS 
    Gets the hostnames for the IP addresses bound to a web site. 
    .DESCRIPTION 
    Gets the hostnames for the IP addresses bound to a web site. Where a host header exists, the host header is used; otherwise, the IP address is looked up 
    in DNS to see if a PTR record exists. 
    .EXAMPLE 
    Get-WebSiteHostname $webSite 
    .EXAMPLE 
    Get-WebSiteHostname -Name 'Default Web Site' 
    .EXAMPLE 
    Get-Website | Get-WebSiteHostname 
    .LINK 
    Get-Website 
    #> 
    [CmdletBinding(SupportsShouldProcess = $false)] 
    param 
    (
     [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] 
     [string] $Name 
    ) 

    process 
    { 
     $siteHostnames = @() 

     foreach ($webSiteName in $Name) 
     { 
      $bindings = Get-WebBinding -Name $Name 

      foreach ($binding in $bindings) 
      { 
       $bindingInfo = $binding.bindingInformation.Split(':') 
       $hostHeader = $bindingInfo[2] 
       $bindingInfoAddress = $null 
       $isValidIP = [System.Net.IPAddress]::TryParse($bindingInfo[0], [ref] $bindingInfoAddress) 
       $siteHostname = $null 

       if ($bindingInfo -eq '*') 
       { 
        Write-Warning "The $($webSiteName) web site has a binding address set to All Unassigned." 
       } 
       elseif ([string]::IsNullOrWhiteSpace($hostHeader) -eq $false) 
       { 
        $siteHostname = $hostHeader 
        Write-Verbose "The $($webSiteName) web site has a host header set to $($siteHostname)." 
       } 
       elseif ($isValidIP -eq $true) 
       { 
        $siteHostname = (Resolve-DnsName $bindingInfoAddress -DnsOnly PTR -ErrorAction SilentlyContinue).NameHost 

        if ($siteHostname -ne $null) 
        { 
         Write-Verbose "The $($webSiteName) web site has an IP Address $($bindingInfoAddress) that resolves to $($siteHostname)." 
        } 
        else 
        { 
         Write-Warning "The $($webSiteName) web site has an IP Address $($bindingInfoAddress) with no PTR record." 
        } 
       } 
      } 

      if ($siteHostname -ne $null) 
      { 
       $siteHostnames += $siteHostname 
      } 
     } 

     return $siteHostnames | Sort -Unique 
    } 
} 

Get-Website | ?{ (Get-WebConfiguration -Filter '/system.web/authentication' -PSPath $_.PSPath).mode -eq 'Windows' } | Get-WebsiteHostname | Add-BackConnectionHostname