简体   繁体   English

尝试通过 powershell 更改 IIS 站点配置时出现 FileLoad 异常

[英]FileLoad Exception when attempting to alter IIS site configurations through powershell

I'm trying to set up an installation PS script to handle the installation and configuration of two application pools/sites.我正在尝试设置一个安装 PS 脚本来处理两个应用程序池/站点的安装和配置。 The creation is handled correctly, and it adjusts the 32-bit applications property fine, but I hit the following error once I try to enable parent paths:正确处理了创建,并且可以很好地调整 32 位应用程序属性,但是一旦我尝试启用父路径,就会遇到以下错误:

System.IO.FileLoadException: This configuration section cannot be used at this path. System.IO.FileLoadException:此配置节不能用于此路径。 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".锁定是默认情况下 (overrideModeDefault="Deny") 或由具有 overrideMode="Deny" 或旧 allowOverride="false" 的位置标记显式设置的。

My code is below - assume all variables are initialized elsewhere.我的代码如下 - 假设所有变量都在其他地方初始化。 I've tried adding a -Location specification, to no avail.我尝试添加 -Location 规范,但无济于事。 I've also tried changing the applicationHost.config settings to 'Allow' on the module front.我还尝试在模块前面将 applicationHost.config 设置更改为“允许”。

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 

Edit: Got it.编辑:明白了。 See answer.见答案。

In C:\Windows\System32\inetsrv\config, there is a config file titled 'applicationHost.config'.在 C:\Windows\System32\inetsrv\config 中有一个名为“applicationHost.config”的配置文件。 Within that, the.asp section's overrideModeDefault needs to be changed from "Deny" to "Allow".其中,.asp 部分的 overrideModeDefault 需要从“拒绝”更改为“允许”。 This resolved the issue.这解决了这个问题。

Now I just have to figure out how to get powershell to make THAT change.现在我只需要弄清楚如何让 powershell 做出改变。 Changing the command to将命令更改为

Set-WebConfigurationProperty -PSPath MACHINE/WEBROOT/APPHOST -Location 'Default Web Site/app2' -Filter System.WebServer/Security/Authentication/AnonymousAuthentication -Name username -Value ""  #ALT ID:001

also did the trick.也成功了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM