@JasonStone-1737 , Summarizing the answer from our discussion in the comments section.
Requirement:
The requirement is to store the connection string for Cosmos DB as an environment variable in Azure App Service for an ASP.NET Core application.
Scenario:
When attempting to store the Cosmos DB connection string as an environment variable in Azure App Service, specifically using the "Connection Strings" feature, the configuration retrieval process for the connection string encounters difficulties.
Issue:
Despite attempts to store the Cosmos DB connection string as an environment variable using the "Connection Strings" feature of Azure App Service, the retrieval of the connection string through calls from Microsoft.Extensions.Configuration
methods, such as IConfiguration.GetConnectionString()
or IConfiguration.GetSection()
, returns null values.
Potential Cause:
The cause of the issue lies in the mismatch between the way Azure App Service handles "Connection Strings" and the configuration retrieval mechanism in the ASP.NET Core application using Microsoft.Extensions.Configuration
. The discrepancy may be related to the specific configuration setup or version compatibility issues.
Resolution:
To resolve the issue, it is suggested to store the Cosmos DB connection string as an "App Setting" environment variable instead of using the "Connection Strings" feature.
View the Azure Cosmos DB keys in application settings
Storing the connection string as an "App Setting" allows for successful retrieval using IConfiguration.GetSection()
. This approach ensures compatibility and successful configuration retrieval within the ASP.NET Core application running on Azure App Service.
-This doc outlines the steps to leverage Connection string prefixes in ASP.NET Core.
Additionally, review and consider updating the application to the latest .NET Core version to address any potential issues or improvements in the configuration code related to Azure App Service integration.
If the answer helped (pointed you in the right direction) > please click Accept Answer