【问题标题】:How to enable Windows Authentication on a Windows Server 2012 IIS website using Powershell?如何使用 Powershell 在 Windows Server 2012 IIS 网站上启用 Windows 身份验证?
【发布时间】:2016-04-11 16:19:30
【问题描述】:

从端到端,如何在 Windows Server 2012 中的 ASP.NET 应用程序上设置 Windows 身份验证?

在早期版本的 IIS 中,您只需在 Web.Config 中设置 <authentication><identity><authorization> 设置即可。

<!-- Web.Config -->
<system.web>
  ...
  <authentication mode="Windows />
  <identity impersonate="false />
  <authorization>
    <allow users="DOMAIN\user1" />
    <allow users="DOMAIN\user2" />
    <deny users="*" />
  </authorization>

现在有一个额外的安全组件要求您在 IIS 站点/webapp 本身上启用身份验证。

我正在为我们的 Window Server 2012 网络服务器编写引导程序脚本,如何在 Powershell 中完成 IIS 的配置?

注意:我将提供一个自我回答。

【问题讨论】:

    标签: asp.net powershell iis windows-server-2012


    【解决方案1】:

    上述Web.Config 不需要更改,这些设置仍然有效。问题是,IIS 本身不会遵守这些设置,因为 Windows 身份验证已在服务器级别默认关闭。

    首先,确保您已安装 Windows 身份验证功能 Web-Windows-Auth 和服务器管理工​​具 -IncludeManagementTools

    Install-WindowsFeature "Web-Windows-Auth" -IncludeManagementTools ; 
    

    接下来,假设您已经创建了名为“AuthSite”的站点,现在我想禁用匿名身份验证并启用 Windows 身份验证。

    Import-Module WebAdministration ;
    
    # disable anonymous
    Set-WebConfigurationProperty `
      -filter "/system.webserver/security/authentication/anonymousAuthentication" `
      -PSPath "IIS:\" `
      -location "AuthSite" `
      -name "enabled" `
      -value "False" ;
    
    # enable Windows authentication
    Set-WebConfigurationProperty `
      -filter "/system.webserver/security/authentication/windowsAuthentication" `
      -PSPath "IIS:\" `
      -location "AuthSite" `
      -name "enabled" `
      -value "True" ;
    

    注意:必须使用-PSPath-Location(不仅仅是-PSPath 上的完整路径),否则您将遇到锁定部分问题:https://stackoverflow.com/a/31416581/740575

    变化:假设您只是在“默认”站点上创建一个 Web 应用程序“AuthWebApp”,只需替换为-location "Default/AuthWebApp"-PSPath 可以保持不变。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多