我需要使用 powershell 自动配置新的 IIS 服务器,并且需要更改表单身份验证功能的功能委派设置(其 overrideMode)。
我基本上希望更改使用此命令时看到的 overrideMode:
Get-WebConfiguration -Filter //system.web/authentication -PSPath 'MACHINE/WEBROOT/APPHOST' | fl *
我可以使用 Set-WebConfiguration 为其他类型的身份验证方法设置它,例如我会做的 Windows 身份验证:
Set-WebConfiguration -Filter //System.webServer/Security/Authentication/windowsAuthentication -PSPath 'MACHINE/WEBROOT/APPHOST' -Metadata overrideMode -Value Allow
但由于某种原因,我不能对 //system.web/authentication 做同样的事情,我不明白为什么。当我尝试时,我收到此错误:
PS H:\> Set-WebConfiguration -Filter //System.web/Authentication -PSPath 'MACHINE/WEBROOT/APPHOST' -Metadata overrideMode -Value Allow
Set-WebConfiguration : Filename: \\?\C:\Windows\system32\inetsrv\config\applicationHost.config
Line number: 974
Error: This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default
(overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
At line:1 char:1
+ Set-WebConfiguration -Filter //System.web/Authentication -PSPath 'MAC ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-WebConfiguration], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.IIs.PowerShell.Provider.SetConfigurationCommand
我做错了什么,如何更改此值?还有一些其他的委托功能似乎也相同。
这适用于 Windows Server 2016 上的 IIS 10
编辑:我注意到,当我使用 IIS 管理器(而不是 Powershell)将委派设置更改为只读时,它通过将其添加到 applicationHost.config 文件中具有 overrideMode="Deny" 的位置来“锁定”该功能。完成此操作后,如果我尝试将其更改回允许使用 Powershell,则会收到错误消息。这就是问题。如果我只使用 powershell 将其设置为允许或拒绝,它不会给出错误,但更改不会反映在 IIS 管理器中。似乎对于某些委派权限,IIS 管理器使用与 Powershell 更改 overrideMode 不同的方法,一旦使用 UI 锁定它,就无法使用 Powershell 解锁它。