How to set UmbracoApplicationUrl in Azure Web Apps with Environment variables

Easily manage your UmbracoApplicationUrl configuration in Azure Web Apps by leveraging environment variables. This guide walks you through the process step-by-step, ensuring your application runs smoothly across development, staging, and production environments

Why Use Azure Environment Variables?#

Environment variables provide a flexible, secure way to manage app configurations, keeping sensitive data like URLs and keys out of your codebase.

Azure Web Apps automatically maps these variables to your application's configuration, making it seamless to switch settings between environments.

Steps to Set UmbracoApplicationUrl in Azure Web Apps#

Step 1: Navigate to Application Settings#

  1. Log in to the Azure Portal.
  2. Open your Web App resource.
  3. Under the "Settings" section in the navigation panel, click on "Environment variables".
  4. You'll be taken to the Configuration page, where you can add or modify Application settings and Connection strings.
UmbracoApplicationUrl in Azure new setting

Azure Web App Environment variables

Step 2: Add the UmbracoApplicationUrl Setting#

1. In the Configuration page, ensure you're in the App settings tab.

2. Click on + New application setting.

3. Set the Name as:

'Umbraco__CMS__WebRouting__UmbracoApplicationUrl'.

(Double underscores __ map to nested JSON structures in appsettings.json)

4. Enter the Value, e.g., https://dev.example.com/.

5. Save the changes and restart your app to apply the new setting.

Umbraco UmbracoApplicationUrl in appsettings.json

Umbraco UmbracoApplicationUrl in appsettings.json

Step 3: Test the Setting in Umbraco#

To verify the environment variable is correctly read by Umbraco, log the value during app startup:

logger.LogInformation($"Current UmbracoApplicationUrl: {umbracoApplicationUrl}");
/// <summary>
/// Configures the application.
/// </summary>
/// <param name="app">The application builder.</param>
/// <param name="env">The web hosting environment.</param>
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<Startup> logger)
{
	// if (env.IsDevelopment())
	// {
	//     app.UseDeveloperExceptionPage();
	// }

	var umbracoApplicationUrl = _config["Umbraco:CMS:WebRouting:UmbracoApplicationUrl"];
	
	logger.LogInformation($"Current UmbracoApplicationUrl: {umbracoApplicationUrl}");
	
	/* Show Error Mode */
	app.UseDeveloperExceptionPage();
	
	app.UseStaticFiles();
	app.UseUnobtrusiveAjax();
	
	app.UseHttpsRedirection();

	app.UseUmbraco()
		.WithMiddleware(u =>
		{
			u.UseBackOffice();
			u.UseWebsite();
		});
}

💡 Expected Output:
The log should display the value of UmbracoApplicationUrl set in Azure.

UmbracoApplicationUrl Log output

You can expect that the updated UmbracoApplicationUrl value is displayed in Umbraco logs during the startup

How Azure Translates Environment Variables#

Azure interprets double underscores "__" as hierarchy delimiters, converting them to nested JSON paths.

💡For example:
Umbraco__CMS__WebRouting__UmbracoApplicationUrl maps to Umbraco:CMS:WebRouting:UmbracoApplicationUrl in your appsettings.json.

This automatic translation makes it easy to manage complex configurations directly in Azure.

Dynamic Configuration with IOptionsMonitor#

For applications requiring real-time configuration updates, ASP.NET Core offers the IOptionsMonitor interface.

This feature is particularly useful in cloud environments where setting changes should reflect without restarting the app.

Here’s how to access UmbracoApplicationUrl dynamically:

public class PlatformHelper
{
    private readonly IOptionsMonitor<WebRoutingSettings> _webRoutingSettings;
    
    public PlatformHelper(IOptionsMonitor<WebRoutingSettings> webRoutingSettings)
    {
        _webRoutingSettings = webRoutingSettings;
    }

    public string GetUmbracoApplicationUrl()
    {
        return _webRoutingSettings.CurrentValue.UmbracoApplicationUrl;
    }
}

Key Benefits:

  • Constructor Injection: The IOptionsMonitor is injected via Dependency Injection (DI), ensuring testability and modularity.
  • Dynamic Access: Any update to the environment variable is reflected without restarting the app.

Why This Matters#

Using environment variables for UmbracoApplicationUrl ensures:

  • Environment-specific configurations for development, staging, and production.
  • Enhanced security by keeping sensitive information out of your codebase.
  • Dynamic updates without downtime, boosting operational efficiency.

What's Next?#

Start using environment variables today for a more secure, scalable setup.

Need more insights on Umbraco and web development?

🌐 Explore Our Blog for expert advice and resources.

↑ Top ↑