You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure App Service部署后操作中如何获取web.config的正确环境路径

路径说明

在Deploy Azure App Service步骤的Post Deployment Action执行上下文中,你可以直接使用Azure内置的WEBROOT_PATH环境变量定位web.config的位置,不需要手动拼接自定义路径:

  • Windows托管的App Service对应的web.config完整路径:%WEBROOT_PATH%\web.config
  • Linux托管/容器化的App Service对应的web.config完整路径:$WEBROOT_PATH/web.config

其中WEBROOT_PATH变量默认指向你应用的发布根目录,也就是web.config所在的目录,直接调用即可。

可用修改脚本示例

你可以直接把对应脚本放到Post Deployment Action的脚本输入框中使用:

Windows环境PowerShell脚本

# 读取web.config
$configFile = Join-Path $env:WEBROOT_PATH "web.config"
$configXml = [xml](Get-Content $configFile -Encoding UTF8)
# 修改stdoutLogEnabled属性
$configXml.configuration.system.webServer.aspNetCore.stdoutLogEnabled = "true"
# 保存修改
$configXml.Save($configFile)

Linux环境Bash脚本

# 直接替换属性值
sed -i 's/stdoutLogEnabled="false"/stdoutLogEnabled="true"/g' $WEBROOT_PATH/web.config

注意:WEBROOT_PATH是Azure App Service默认预置的全局环境变量,在部署动作的运行上下文中可以直接读取,无需额外配置。如果你的项目发布包根目录确实包含web.config,该路径可以100%匹配到目标文件。

内容的提问来源于stack exchange,提问作者Matt W

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 12:09:04