AZ-204 Develop Azure compute solutions Practice Question
You are developing a web app that runs on Azure App Service. The app needs to read a connection string from configuration. Which is the recommended approach to access the connection string in the app code?
⚠ Common exam trap
Many candidates assume IConfiguration or appsettings.json is the primary source for connection strings, but Azure App Service overrides these with environment variables when connection strings are configured in the portal, and the exam expects you to know the specific prefix-based environment variable naming convention.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use Environment.GetEnvironmentVariable("SQLAZURECONNSTR_MyConn")
Azure App Service automatically injects connection strings defined in the 'Connection strings' blade as environment variables with a specific prefix. For SQL Azure, the prefix is 'SQLAZURECONNSTR_', so the environment variable name becomes 'SQLAZURECONNSTR_MyConn'. Using Environment.GetEnvironmentVariable is the recommended way to retrieve these values at runtime, as they are securely stored and managed by the platform.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Call an HTTP endpoint on the App Service instance
Why it's wrong here
Calling an HTTP endpoint on the App Service instance to retrieve connection strings is not a supported or secure mechanism. Azure App Service does not expose a public API for applications to query their own configuration secrets directly via HTTP. Such an approach would introduce significant security vulnerabilities, as configuration is designed to be injected into the application's process environment, not exposed externally.
- ✓
Use Environment.GetEnvironmentVariable("SQLAZURECONNSTR_MyConn")
Why this is correct
When connection strings are configured in Azure App Service settings, the platform automatically injects them into the application's process as environment variables. App Service prefixes these variables based on the connection string type, such as "SQLAZURECONNSTR_" for SQL Database connections. Therefore, accessing Environment.GetEnvironmentVariable("SQLAZURECONNSTR_MyConn") is the direct and recommended method for the application to retrieve these pre-configured secrets.
- ✗
Use Azure.Identity.DefaultAzureCredential and Key Vault
Why it's wrong here
While Azure Key Vault is a robust and highly recommended solution for securely storing application secrets, and Azure.Identity.DefaultAzureCredential is the correct way to access it, this option is not the most direct answer if the connection string is already configured within the App Service settings. Using Key Vault would typically involve the application explicitly retrieving secrets from Key Vault, rather than relying on App Service's native environment variable injection for its own configured settings. The question implies accessing a connection string configured directly in App Service.
- ✗
Read from appsettings.json using IConfiguration
Why it's wrong here
Reading connection strings directly from appsettings.json using IConfiguration is appropriate for local development and non-sensitive configuration. However, storing production secrets like database connection strings directly within appsettings.json and deploying them is a significant security anti-pattern. This practice would embed sensitive information directly into source control and deployed artifacts, making it vulnerable and non-compliant with best practices for secret management in cloud environments.
Go deeper
Related to this question
About these practice questions
One of 881 original AZ-204 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This AZ-204 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AZ-204 exam.