使用AppCmd仅在APPHOST中列出配置 [英] Use AppCmd to LIST CONFIG in APPHOST only
问题描述
我需要使用Powershell在尚未将代码部署到文件系统上的Web应用程序上配置IIS7.5(可能根本存在旧的/损坏的web.config).我希望能够在APPHOST级别上完成所有这些操作. (有关使用Powershell> AppCmd的底部,请注意).
I have a requirement to use powershell to configure IIS7.5 on WebApplications that have not yet had code deployed (possibly at all, possibly old/broken web.configs exist) to the file system. I would like to be able to do this all at the APPHOST level. (Note at the bottom about use of Powershell > AppCmd).
我可以正确设置所有值,但是,在勤奋工作的同时,我还希望通过在设置后检索它们来验证是否正确设置了这些值.
I can SET all the values properly, however, being somewhat diligent, I like to also validate the values were set properly by retrieving them after setting.
这是场景: 我可以使用AppCmd设置此值,以便使用/Commit:APPHOST标志在APPHOST级别应用该设置.但是,我还没有找到一种专门在APPHOST级别上读取值的方法.
Here's the scenario: I can set this value using AppCmd so the setting is applied at the APPHOST level using the /Commit:APPHOST flag. However, I havent found a way to READ the values exclusively at the APPHOST level.
设置代码成功:
C:\Windows\System32\inetsrv\appcmd.exe set config "webSiteName/webAppName" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:"True" /commit:apphost
但是,我找不到使用AppCmd(或Powershell)读取值的方法: 由于文件夹中预先存在的web.config损坏,运行以下AppCmd会返回错误(具体错误并不重要,因为它正在读取WebApp的web.config而不是ApplicationHost.config/APPHOST)
However, I cant find a way to read the values using AppCmd (or Powershell): Running the following AppCmd returns an error due to the broken pre-existing web.config in the folder (the specific error is unimportant, as it is reading the WebApp's web.config instead of the ApplicationHost.config/APPHOST):
C:\Windows\System32\inetsrv\appcmd.exe list config "MACHINE/WEBROOT/APPHOST/webSiteName/webAppName" -section:system.webServer/security/authentication/anonymousAuthentication
ERROR ( message:Configuration error
Filename: \\?\c:\inetpub\wwwroot\webSiteName\webAppName\web.config
Line Number: 254
Description: The configuration section 'system.runtime.caching' cannot be read because it is missing a section declaration
. )
注意:我宁愿在Powershell中而不是使用AppCmd来完成所有操作,因此,如果任何人都有语法来修改位于Powershell内部的WebApplication(位于Web站点下)的WebApplication的AnonymousAuthentication部分的APPHOST设置,似乎只使用WebApp web.config),那将是非常棒的,非常感谢!
Note: I would prefer to do this all in Powershell instead of using AppCmd, so if anyone has the syntax for modifying the APPHOST settings for anonymousAuthentication section of a WebApplication, that lives under a Website, from inside Powershell (Get-WebConfiguration seems to only use the WebApp web.config), that would be totally awesome and much appreciated!
推荐答案
在PowerShell中执行此操作的方法如下:
Here's how to do this in PowerShell:
[Reflection.Assembly]::Load(
"Microsoft.Web.Administration, Version=7.0.0.0,
Culture=Neutral, PublicKeyToken=31bf3856ad364e35") > $null
$serverManager = New-Object Microsoft.Web.Administration.ServerManager
$config = $serverManager.GetApplicationHostConfiguration()
$anonymousAuthenticationSection = $config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "simpleasp.net")
Write-Host "Current value: " $anonymousAuthenticationSection["enabled"]
# Now set new value
$anonymousAuthenticationSection["enabled"] = $true
$serverManager.CommitChanges()
这篇关于使用AppCmd仅在APPHOST中列出配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!