Azure Web App交换槽时,如何配置槽特定设置保留redirectUrl不被交换
配置Azure Web App槽特定的redirectUrl设置(避免交换时被覆盖)
要让preprod槽的redirectUrl设置在槽交换时不被替换,核心是将该配置标记为槽特定设置(Slot Setting)——这类设置会绑定到槽本身,不会随槽交换操作同步到目标槽。以下是具体实现方式:
一、Azure门户手动配置
- 登录Azure门户,打开目标Web App,切换到「部署槽」面板,选中preprod槽
- 进入「配置」>「应用设置」页面,找到
redirectUrl配置项 - 勾选该配置项右侧的「槽设置」复选框,点击「保存」完成配置
二、Azure DevOps Pipeline自动化配置
1. 使用Azure CLI任务
在流水线中添加Azure CLI任务,执行以下命令将redirectUrl标记为preprod槽的特定设置:
az webapp config appsettings set --name <你的WebApp名称> --resource-group <资源组名称> --slot preprod --settings redirectUrl="https://preprod-your-app.com" --slot-settings redirectUrl
参数说明:
--slot-settings:指定该配置项为槽特定设置- 替换
<你的WebApp名称>和<资源组名称>为实际值,redirectUrl的值设为preprod环境需要的验证地址
2. 使用Azure PowerShell任务
若偏好PowerShell,可添加Azure PowerShell任务执行以下命令:
Set-AzWebAppSlot -ResourceGroupName <资源组名称> -Name <WebApp名称> -Slot preprod -AppSettings @{redirectUrl="https://preprod-your-app.com"} -SlotSettingNames @("redirectUrl")
3. 使用Azure App Service Deploy任务
在Azure App Service Deploy任务的「应用设置」区域:
- 添加
redirectUrl配置项,填入preprod环境的目标值 - 在该配置项的「槽设置」列勾选复选框,部署时会自动将其标记为槽特定设置
效果说明
将redirectUrl设为槽特定设置后:
- 交换preprod与production槽时,preprod槽的
redirectUrl会保留在preprod槽中,不会覆盖production槽的对应配置 - production槽的
redirectUrl配置也不会同步到preprod槽,确保交换前后两个槽的redirectUrl各自独立,满足你在交换前验证preprod应用状态的需求
内容的提问来源于stack exchange,提问作者Khalil
相关产品推荐
相关产品推荐

