尝试通过 powershell 更改 IIS 站点配置时出现 FileLoad 异常
FileLoad Exception when attempting to alter IIS site configurations through powershell
我正在尝试设置安装 PS 脚本来处理两个应用程序 pools/sites 的安装和配置。创建处理正确,它可以很好地调整 32 位应用程序 属性,但是一旦我尝试启用父路径,我就会遇到以下错误:
System.IO.FileLoadException: 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".
我的代码如下 - 假设所有变量都在别处初始化。我尝试添加 -Location 规范,但无济于事。我还尝试将模块前端的 applicationHost.config 设置更改为 'Allow'。
New-WebAppPool app1
New-WebAppPool app2
#Creates a new webapplication under Default Web Sites
New-WebApplication -Name app1 -Site 'Default Web Site' -PhysicalPath $srcPath -ApplicationPool app1
New-WebApplication -Name app2 -Site 'Default Web Site' -PhysicalPath $MCCPath -ApplicationPool app2 #ALT ID:001
Set-Location IIS:\;
#Sets app1's app pool to enable 32 bit.
Set-ItemProperty -Path IIS:\AppPools\app1 -Name enable32BitAppOnWin64 -Value true #ALT ID:001
#Sets ASP enable parent path to true (THIS is where it throws the error)
Set-WebConfigurationProperty -PSPath 'IIS:\Sites\Default Web Site\app1' -Filter system.webServer/asp -Name enableParentPaths -Value $true #ALT ID:001
Set-WebConfigurationProperty -PSPath 'IIS:\Sites\Default Web Site\app2' -Filter system.webServer/asp -Name enableParentPaths -Value $true #ALT ID:001
#Sets AnonymousAuthentication to use app pool identity
Set-WebConfigurationProperty -PSPath 'IIS:\Sites\Default Web Site\app1' -Filter System.WebServer/Security/Authentication/AnonymousAuthentication -Name username -Value "" -Location MyLocation #ALT ID:001
Set-WebConfigurationProperty -PSPath 'IIS:\Sites\Default Web Site\app2' -Filter System.WebServer/Security/Authentication/AnonymousAuthentication -Name username -Value "" -Location MyLocation #ALT ID:001
#Sets Windows AD user as pass thru within app pools
Set-ItemProperty -Path IIS:\AppPools\app1 -Name processModel -Value @{userName = "$usrName";password="$usrPswd";identitytype=3} #ALT ID:001
Set-ItemProperty -Path IIS:\AppPools\app2 -Name processModel -Value @{userName = "$usrName";password="$usrPswd";identitytype=3} #ALT ID:001
编辑:知道了。查看答案。
在 C:\Windows\System32\inetsrv\config 中,有一个名为 'applicationHost.config' 的配置文件。其中,.asp 部分的 overrideModeDefault 需要从“拒绝”更改为“允许”。这解决了问题。
现在我只需要弄清楚如何获取 powershell 来进行更改。
将命令更改为
Set-WebConfigurationProperty -PSPath MACHINE/WEBROOT/APPHOST -Location 'Default Web Site/app2' -Filter System.WebServer/Security/Authentication/AnonymousAuthentication -Name username -Value "" #ALT ID:001
也成功了。
我正在尝试设置安装 PS 脚本来处理两个应用程序 pools/sites 的安装和配置。创建处理正确,它可以很好地调整 32 位应用程序 属性,但是一旦我尝试启用父路径,我就会遇到以下错误:
System.IO.FileLoadException: 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".
我的代码如下 - 假设所有变量都在别处初始化。我尝试添加 -Location 规范,但无济于事。我还尝试将模块前端的 applicationHost.config 设置更改为 'Allow'。
New-WebAppPool app1
New-WebAppPool app2
#Creates a new webapplication under Default Web Sites
New-WebApplication -Name app1 -Site 'Default Web Site' -PhysicalPath $srcPath -ApplicationPool app1
New-WebApplication -Name app2 -Site 'Default Web Site' -PhysicalPath $MCCPath -ApplicationPool app2 #ALT ID:001
Set-Location IIS:\;
#Sets app1's app pool to enable 32 bit.
Set-ItemProperty -Path IIS:\AppPools\app1 -Name enable32BitAppOnWin64 -Value true #ALT ID:001
#Sets ASP enable parent path to true (THIS is where it throws the error)
Set-WebConfigurationProperty -PSPath 'IIS:\Sites\Default Web Site\app1' -Filter system.webServer/asp -Name enableParentPaths -Value $true #ALT ID:001
Set-WebConfigurationProperty -PSPath 'IIS:\Sites\Default Web Site\app2' -Filter system.webServer/asp -Name enableParentPaths -Value $true #ALT ID:001
#Sets AnonymousAuthentication to use app pool identity
Set-WebConfigurationProperty -PSPath 'IIS:\Sites\Default Web Site\app1' -Filter System.WebServer/Security/Authentication/AnonymousAuthentication -Name username -Value "" -Location MyLocation #ALT ID:001
Set-WebConfigurationProperty -PSPath 'IIS:\Sites\Default Web Site\app2' -Filter System.WebServer/Security/Authentication/AnonymousAuthentication -Name username -Value "" -Location MyLocation #ALT ID:001
#Sets Windows AD user as pass thru within app pools
Set-ItemProperty -Path IIS:\AppPools\app1 -Name processModel -Value @{userName = "$usrName";password="$usrPswd";identitytype=3} #ALT ID:001
Set-ItemProperty -Path IIS:\AppPools\app2 -Name processModel -Value @{userName = "$usrName";password="$usrPswd";identitytype=3} #ALT ID:001
编辑:知道了。查看答案。
在 C:\Windows\System32\inetsrv\config 中,有一个名为 'applicationHost.config' 的配置文件。其中,.asp 部分的 overrideModeDefault 需要从“拒绝”更改为“允许”。这解决了问题。
现在我只需要弄清楚如何获取 powershell 来进行更改。 将命令更改为
Set-WebConfigurationProperty -PSPath MACHINE/WEBROOT/APPHOST -Location 'Default Web Site/app2' -Filter System.WebServer/Security/Authentication/AnonymousAuthentication -Name username -Value "" #ALT ID:001
也成功了。