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

Azure Web Apps GitHub部署时web.config转换及连接字符串问题咨询

Fixing Umbraco Connection String Issues with Web.config Transformations in Azure Web Apps

Absolutely! Web.config transformations are fully supported in Azure Web Apps when using GitHub deployment, and they’re a perfect solution for resolving your post-deployment connection errors with Umbraco. Let’s break down how to implement this properly:

1. Add Transformation Files to Your Umbraco Project

First, make sure you have the right config transformation files in your project. Visual Studio usually creates Web.Debug.config and Web.Release.config by default, but you can create a dedicated one for Azure (like Web.Azure.config) if you prefer:

  • Right-click your root web.config in Visual Studio → Add Config Transformation
  • Rename the new file to Web.Azure.config to keep your environments organized

2. Define the Connection String Transformation

Umbraco relies on the umbracoDbDSN connection string for its database. In your transformation file (e.g., Web.Azure.config), add this code to overwrite the local connection string with your Azure SQL details:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add 
      name="umbracoDbDSN" 
      connectionString="Server=tcp:YOUR_SERVER_NAME.database.windows.net,1433;Initial Catalog=YOUR_DB_NAME;Persist Security Info=False;User ID=YOUR_DB_USER;Password=YOUR_DB_PASSWORD;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" 
      providerName="System.Data.SqlClient" 
      xdt:Transform="SetAttributes" 
      xdt:Locator="Match(name)"
    />
  </connectionStrings>
</configuration>
  • The xdt:Locator="Match(name)" targets the exact connection string by its name, and xdt:Transform="SetAttributes" overwrites its values with your Azure-specific details.

3. Tell Azure to Apply the Transformation During Deployment

There are two straightforward ways to trigger the transformation when deploying from GitHub:

Option 1: Use Azure App Settings (Simplest)

  • Navigate to your Azure Web App → Configuration → Application settings
  • Add a new setting with:
    • Key: SCM_BUILD_ARGS
    • Value: /p:TransformConfigFiles=true /p:Configuration=Azure
      Note: Replace Azure with Release if you’re using Web.Release.config instead of a custom Web.Azure.config.

Option 2: Custom Kudu Deployment Script (More Control)

If you want fine-grained control over the deployment process, generate a custom Kudu script:

  1. Run this command in your project directory (use Azure CLI locally or in Cloud Shell):
    az webapp deployment script --resource-group YOUR_RESOURCE_GROUP --name YOUR_WEB_APP --script-type bash --output-path .deployments/deploy.sh
    
  2. Open the generated deploy.sh file, find the MSBuild command, and add the transformation arguments:
    MSBuild "$DEPLOYMENT_SOURCE/YourUmbracoProject.csproj" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="$DEPLOYMENT_TEMP" /p:AutoParameterizationWebConfigConnectionStrings=false /p:TransformConfigFiles=true /p:Configuration=Azure
    
  3. Commit this script to your GitHub branch so Azure uses it during deployment.

4. Verify the Transformation Worked

After deploying, you can confirm the connection string was updated correctly:

  • Go to your Web App → Advanced Tools → Go (opens the Kudu portal)
  • Navigate to site/wwwroot and open the web.config file. Check that the umbracoDbDSN matches what you defined in the transformation file.

Alternative: Use Azure App Settings to Override Connection Strings

For an even simpler approach (and better security, since you won’t commit sensitive credentials to GitHub), you can override the connection string directly in Azure:

  • Go to your Web App → Configuration → Connection strings
  • Add a new connection string with:
    • Name: umbracoDbDSN
    • Value: Your Azure SQL connection string
    • Type: SQLAzure
      Azure will automatically replace the connection string in your web.config at runtime—no transformations needed!

内容的提问来源于stack exchange,提问作者Eric Shay

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 04:09:00