Jump to Section
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#
- Log in to the Azure Portal.
- Open your Web App resource.
- Under the "Settings" section in the navigation panel, click on "Environment variables".
- You'll be taken to the Configuration page, where you can add or modify Application settings and Connection strings.
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.
Step 3: Test the Setting in Umbraco#
To verify the environment variable is correctly read by Umbraco, log the value during app startup:
💡 Expected Output:
The log should display the value of UmbracoApplicationUrl set in Azure.
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:
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.