2013-07-04 34 views
32

Gần đây, tôi đã gặp sự cố khó chịu khi xác thực Windows để hoạt động trên phiên bản cục bộ của IIS 7.5 (Windows 7 Pro) đến trang web ASP.net 4.0. Tôi đã làm theo các bước cơ bản.Xác thực Windows không hoạt động trên IIS 7.5 cục bộ. Lỗi 401.1

IIS xác thực

  • Disable Anonymous Xác thực
  • Enable Windows Authentication

Sửa web.config

<authentication mode="Windows" /> 

này đã làm một công việc tốt đẹp của phép Windows Authentication nhưng mọi nỗ lực để đăng nhập bị từ chối và cuối cùng trả về Lỗi 401.1. Đây là nơi bắt đầu vấn đề. Dường như có nhiều lý do cho điều này được ghi lại trên web bao gồm cả ở đây trên Stack Overflow.

tôi đã cố gắng:

  • 'Advanced settings' Editing IIS xác thực cho Windows Authentication để vô hiệu hóa Mở rộng bảo vệ và Kernel-mode authentication
  • Editing IIS xác thực 'cung cấp' để di chuyển NTLM trên Negotiate.
  • Chỉnh sửa quy tắc ủy quyền IIS .NET để giải thích Cho phép người dùng (và nhiều kết hợp khác).
  • Nhiều dòng lệnh và chỉnh sửa dòng lệnh IIS khác nhau.
  • Chỉnh sửa cấu hình khác nhau trong tệp web.config.
  • Thậm chí một số chỉnh sửa quyền của hệ thống tệp.

Nhưng tất cả không có kết quả, 401.1 đáng sợ vẫn tồn tại.

Đây thực sự là trường hợp "không thể thấy gỗ cho cây". Không có giải pháp nào tôi tìm thấy (gọi đó là trường hợp các thông số tìm kiếm xấu nếu bạn muốn) làm việc cho tôi vì vậy tôi nghĩ rằng nó đáng để đăng câu hỏi này, hy vọng, cung cấp câu trả lời rõ ràng dễ tìm hơn cho bất kỳ ai gặp vấn đề tương tự .

Trả lời

62

Vấn đề ở đây là các phiên bản Windows hiện đại (Windows XP SP2, Windows Server 2003 SP1 trở lên) bao gồm tính năng bảo mật kiểm tra vòng lặp được thiết kế để giúp ngăn chặn các cuộc tấn công phản chiếu trên máy tính của bạn. Do đó, xác thực không thành công nếu FQDN hoặc tiêu đề máy chủ tùy chỉnh mà bạn sử dụng không khớp với tên máy tính cục bộ.

Điều này có thể được giải quyết bằng cách chỉ định rõ tên máy chủ hoặc bằng cách tắt kiểm tra vòng lặp. Rõ ràng trước đây là cách tiếp cận được kiểm soát nhiều hơn.

  1. Đặt mục DisableStrictNameChecking registry để 1. Xem: 281308(Lưu ý: Tôi không cần làm điều này)
  2. Trong Registry Editor, xác định vị trí và sau đó nhấp vào khóa registry sau đây: HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Lsa \ MSV1_0
  3. Bấm chuột phải vào MSV1_0, trỏ chuột vào Mới, sau đó bấm Giá trị nhiều chuỗi.
  4. Loại BackConnectionHostNames, sau đó nhấn ENTER.
  5. Bấm chuột phải vào BackConnectionHostNames, sau đó bấm Sửa đổi.
  6. Trong hộp Dữ liệu giá trị, hãy nhập tên máy chủ hoặc tên máy chủ lưu trữ cho các trang web trên máy tính cục bộ, sau đó bấm OK.
  7. Thoát khỏi Registry Editor, sau đó khởi động lại dịch vụ IISAdmin.

Chi tiết đầy đủ về cách thực hiện việc này có thể được tìm thấy trên MSDN: 896861

Hy vọng điều này sẽ giúp người ra. Nếu bạn có bất kỳ gợi ý hoặc cải tiến thay thế nào, vui lòng thêm.

+1

Trong trường hợp của tôi, nó đơn giản như sử dụng http: // localhost/thay vì http://foobar.com/ address. Cảm ơn bạn đã chỉ cho tôi theo hướng này. –

+1

Thật không may này didnt làm việc cho tôi hoặc. Vấn đề của tôi là cửa sổ đăng nhập phương thức tiếp tục hiển thị. – joey

+1

Tôi đã có thể giải quyết sự cố bằng cách thêm ràng buộc trong IIS và sử dụng tên máy chủ làm tên máy của tôi. Điều đó giải quyết nó cho tôi. – joey

1

Cài đặt lại các tính năng IIS của bạn một lần nữa và đảm bảo rằng các ô kiểm tra auth Windows được chọn.

3

Tôi muốn thêm nhận xét của Michael Dark làm câu trả lời vì tôi không có quyền sửa đổi sổ đăng ký của mình nên câu trả lời của Pete không hiệu quả đối với tôi nhưng tôi có thể giải quyết được vấn đề.

Tôi đã giải quyết nó bằng cách thêm một Ràng buộc mới vào trang web của tôi mà không có tên máy chủ được chỉ định và cổng khác (vì localhost: 80 được sử dụng cho tôi). Ngay sau khi tôi thử gọi nó từ http://localhost:86/mypage, nó hoạt động. Sau khi kiểm tra nhanh trong trình duyệt, tôi đã thử nghiệm một vài lần với cURL và nó đã được chấp nhận và từ chối thông tin đăng nhập của tôi một cách chính xác.

+0

Điều này thực sự làm việc cho tôi là tốt. Thậm chí không nghĩ đến việc thay đổi ràng buộc máy chủ, nhưng khi tôi làm việc đó ngay lập tức. Bất kỳ ý tưởng gì gây ra điều này? – smoksnes

+0

Câu hỏi Nevermind ở trên. Tôi đã thử các giải pháp từ PeteWifi và nó hoạt động rất tốt là tốt. – smoksnes

1

Đây là mã PowerShell mà tôi sử dụng để xử lý các tên máy chủ kết nối ngược và IIS. Lưu ý rằng với một công việc nhỏ, các lệnh có thể được lưu vào một mô-đun và sử dụng theo cách đó.

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