且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Powershell中为IIS应用程序启用身份验证

更新时间:2023-02-25 20:48:39

您不需要单独的 -PSPath -Location 参数。你可以像这样组合它们:

You don't need separate -PSPath and -Location parameters. You can combine them like this:

-PSPath "IIS:\Sites\$SiteName\$AppName"

所以实际命令如下所示:

So the actual command will look like this:

Set-WebConfigurationProperty -Filter "/system.webServer/security/authentication/windowsAuthentication" -Name Enabled -Value True -PSPath "IIS:\Sites\$SiteName\$AppName"

请注意,您可能会遇到此错误:

Note that you may run into this error:

Set-WebConfigurationProperty:此配置部分不能在此路径中使用。当该部分被锁定在父级别时会发生这种情况。锁定是默认情况下(overrideModeDefault =Deny),或由locationMode =Deny或旧版allowOverride =false的位置标记显式设置。

Tomfanning在ServerFault上提供了此处的解决方案。我在这里重复了他的步骤:

Tomfanning over at ServerFault provided the solution here. I have repeated his steps here:


  1. 打开IIS管理器

  2. 单击树中的服务器名称在左侧

  3. 右侧窗格,管理部分,双击配置编辑器

  4. 在顶部,选择system.webServer / security / authentication部分/ anonymousAuthentication

  5. 右侧窗格,单击解锁部分

  6. 在顶部,选择system.webServer / security / authentication / windowsAuthentication
  7. 部分>
  8. 右侧窗格,单击解锁部分

  1. Open IIS Manager
  2. Click the server name in the tree on the left
  3. Right hand pane, Management section, double click Configuration Editor
  4. At the top, choose the section system.webServer/security/authentication/anonymousAuthentication
  5. Right hand pane, click Unlock Section
  6. At the top, choose the section system.webServer/security/authentication/windowsAuthentication
  7. Right hand pane, click Unlock Section