仅使用 AppCmd 在 APPHOST 中列出配置

发布于 2024-12-29 05:08:06 字数 1322 浏览 1 评论 0原文

我需要使用 powershell 在尚未将代码部署到文件系统(可能根本没有,可能存在旧/损坏的 web.configs)的 Web 应用程序上配置 IIS7.5。我希望能够在 APPHOST 级别完成这一切。 (请注意底部有关 Powershell > AppCmd 的使用)。

我可以正确设置所有值,但是,有点勤奋,我还喜欢通过在设置后检索它们来验证这些值是否设置正确。

这是场景: 我可以使用 AppCmd 设置此值,以便使用 /Commit:APPHOST 标志在 APPHOST 级别应用该设置。但是,我还没有找到一种方法来专门在 APPHOST 级别读取这些值。

设置代码成功:

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):

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 内部修改位于网站下的 Web 应用程序的匿名身份验证部分的 APPHOST 设置的语法(Get-WebConfiguration 似乎只使用 WebApp web.config),那将是非常棒的,非常感谢!

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.

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.

Setting the Code is successful:

C:\Windows\System32\inetsrv\appcmd.exe set config "webSiteName/webAppName" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:"True" /commit: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
. )

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

世界和平 2025-01-05 05:08:06

以下是在 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()

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文