5

我需要使用 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 解锁它。

4

1 回答 1

0

您可以检查以确保从这篇文章中启用了这些 Windows 功能,因为这解决了那里的某些错误:

配置错误:此配置部分不能用于此路径

您是否可以在文件上设置属性使其不是只读的?

# You may need to use the -Credential parameter for this to work on a remote machine
Set-ItemProperty \\?\C:\Windows\system32\inetsrv\config\applicationHost.config -name IsReadOnly -value $false

然后尝试重新运行您的Set-WebConfiguration命令。

您还可以尝试将该配置文件作为 XML 加载到 PowerShell 中,然后修改overrideMode属性并将其保存回 IIS 路径。

[xml]$XmlDoc = Get-Content -Path '\\?\C:\Windows\system32\inetsrv\config\applicationHost.config'
# '//System.Web/Authentication' is the XPath provided above
$AuthNode = $XMLdoc.SelectSingleNode('//System.Web/Authentication')
$AuthNode.overrideMode = "Allow"
$XmlDoc.Save("\\?\C:\Windows\system32\inetsrv\config\applicationHost.config")

我没有在这台机器上设置 IIS,但假设它是 XML 中的有效 XPATH,你应该能够更改标志,假设当你尝试更新它时没有使用该文件。

于 2018-09-28T02:30:23.450 回答