在Powershell中以编程方式解锁IIS配置部分
|
我正在编写一个Powershell脚本来创建和配置许多网站和虚拟目录。我正在使用.NET Microsoft.Web.Administration程序集。我已经在默认网站下创建了一个新应用程序,并向其添加了新的虚拟目录,并且一切正常。我现在想做的是为虚拟目录设置身份验证选项。我在Powershell中执行以下操作:
[System.Reflection.Assembly]::LoadWithPartialName(\"Microsoft.Web.Administration\")
$oIIS = new-object Microsoft.Web.Administration.ServerManager
$oWebSite = $oIIS.Sites[\"Default Web Site\"]
$oApp = $oWebSite.Applications[\"/MyApp\"]
$oConfig = $oApp.GetWebConfiguration()
$oAnonAuth = $oConfig.GetSection(\"system.webServer/security/authentication/anonymousAuthentication\")
$oAnonAuth.SetAttributeValue(\"enabled\", \"False\")
但是,SetAttributeValue命令给我以下错误:
\“此配置节无法在此路径上使用。当该节被锁定在父级时会发生。默认情况下,锁定是(overrideModeDefault = \” Deny \“),或者是由具有overrideMode = \的位置标记明确设置的“ Deny \”或旧版allowOverride = \“ false \”
根据我在其他地方阅读的内容,有一些建议可以更改应用程序的XML文件以允许覆盖。我不想这样做-有什么办法以编程方式解锁配置以允许我进行更改?我根本不希望任何用户输入此过程。
谢谢你的帮助,
铝
找到了我一直在寻找的答案-但是作为新用户,我无法在24小时内回答自己的问题。
我想我在此站点上找到了下面的代码,但是由于我的机器已重新启动,因此我丢失了该页面。但是,以下方法似乎有效:
#
# Allow overriding of the security settings.
#
$oGlobalConfig = $oIIS.GetApplicationHostConfiguration()
$oConfig = $oGlobalConfig.GetSection(\"system.webServer/security/authentication/anonymousAuthentication\", \"Default Web Site/mySite\")
$oConfig.OverrideMode=\"Allow\"
$oIIS.CommitChanges()
#
# Following the commit above, we need a new instance of the configuration object, which we can now
# modify.
#
$oGlobalConfig = $oIIS.GetApplicationHostConfiguration()
$oConfig = $oGlobalConfig.GetSection(\"system.webServer/security/authentication/anonymousAuthentication\", \"Default Web Site/mySite\")
$oConfig.SetAttributeValue(\"enabled\", \"False\")
$oIIS.CommitChanges()
没有找到相关结果
已邀请:
1 个回复
铰齐插
您的解决方案相似但相异,以至于我无法验证您所拥有的,但是由于您说的可行,所以听起来不错。 :)