You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/howto-labels-aspnet-core.md
+15-17Lines changed: 15 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,28 +11,28 @@ ms.author: lcozzens
11
11
---
12
12
# Use labels to enable configurations for different environments
13
13
14
-
Many applications need to use different configurations for different environments. For example, suppose that an application has a configuration value that defines the connection string to use for its back-end database. The application developers use a different database from the one used in production. The database connection string used by the application must change as the application moves from development to production.
14
+
Many applications need to use different configurations for different environments. Suppose that an application has a configuration value that defines the connection string to use for its back-end database. The application developers use a different database from the one used in production. The database connection string that the application uses must change as the application moves from development to production.
15
15
16
-
In Azure App Configuration, you can use *labels* to define different values for the same key. For example, you can define a single key with different values for *Development* and *Production*. You can specify which label to load when connecting to App Configuration.
16
+
In Azure App Configuration, you can use *labels* to define different values for the same key. For example, you can define a single key with different values for development and production. You can specify which label to load when connecting to App Configuration.
17
17
18
-
To demonstrate this functionality, you'll modify the web app created in [Quickstart: Create an ASP.NET Core app with Azure App Configuration](./quickstart-aspnet-core-app.md) to use different configuration settings for development versus production. Complete the Quickstart before proceeding.
18
+
To demonstrate this functionality, you'll modify the web app created in [Quickstart: Create an ASP.NET Core app with Azure App Configuration](./quickstart-aspnet-core-app.md) to use different configuration settings for development versus production. Complete the quickstart before proceeding.
19
19
20
20
## Specify a label when adding a configuration value
21
21
22
-
1.In the Azure portal, go to **Configuration Explorer** and locate the *TestApp:Settings:FontColor* key that you created in the Quickstart. Select its context menu and then click **Add Value**.
22
+
In the Azure portal, go to **Configuration Explorer** and find the *TestApp:Settings:FontColor* key that you created in the quickstart. Select its context menu and then click **Add Value**.
23
23
24
24
> [!div class="mx-imgBorder"]
25
25
> 
26
26
27
-
1.On the **Add Value** screen, enter a **Value** of **red** and a **Label** of **Development**. Leave **Content type** empty. Select **Apply**.
27
+
On the **Add Value** screen, enter a **Value** of **red** and a **Label** of **Development**. Leave **Content type** empty. Select **Apply**.
28
28
29
29
## Load configuration values with a specified label
30
30
31
-
By default, App Configuration only loads configuration values with no label. If you've defined labels for your configuration values, you'll want to specify the label(s) to use when connecting to App Configuration.
31
+
By default, Azure App Configuration only loads configuration values with no label. If you've defined labels for your configuration values, you'll want to specify the labels to use when connecting to App Configuration.
32
32
33
-
In the previous section, you created a different configuration value for the *Development* environment. You use the `HostingEnvironment.EnvironmentName` variable to dynamically determine which environment the app currently runs in. To learn more, see [Use multiple environments in ASP.NET Core](/aspnet/core/fundamentals/environments).
33
+
In the previous section, you created a different configuration value for the development environment. You use the `HostingEnvironment.EnvironmentName` variable to dynamically determine which environment the app currently runs in. To learn more, see [Use multiple environments in ASP.NET Core](/aspnet/core/fundamentals/environments).
34
34
35
-
-Load configuration values with the label corresponding to the current environment by passing the environment name into the `Select` method:
35
+
Load configuration values with the label corresponding to the current environment by passing the environment name into the `Select` method:
36
36
37
37
```csharp
38
38
public static IHostBuilder CreateHostBuilder(string[] args) =>
@@ -53,29 +53,27 @@ In the previous section, you created a different configuration value for the *De
> The preceding code snippet loads the App Configuration connection string from an environment variable named`AppConfigConnectionString`. Be sure that this environment variable is set properly.
58
58
59
-
Thiscallsthe`Select` methodtwice. Thefirsttime, itloadsconfigurationvalueswithnolabel. Then, itloadsconfigurationvalueswiththelabelcorrespondingtothecurrentenvironment. Theseenvironment-specificvaluesoverrideanycorrespondingvalueswithnolabel. Youdon't need to define environment-specific values for every key. If a key doesn'thaveavaluewithalabelcorrespondingtothecurrentenvironment, itusesthevaluewithnolabel.
59
+
The `Select` method is called twice. The first time, it loads configuration values with no label. Then, it loads configuration values with the label corresponding to the current environment. These environment-specific values override any corresponding values with no label. You don't need to define environment-specific values for every key. If a key doesn't have a value with a label corresponding to the current environment, it uses the value with no label.
Open the `launchSettings.json` file under the `Properties` directory. Find the `config` entry under `profiles`. In the `environmentVariables` section, set the `ASPNETCORE_ENVIRONMENT` variable to `Production`.
With the new values set, build and run your application.
68
66
69
67
```dotnetcli
70
68
dotnet build
71
69
dotnet run
72
70
```
73
71
74
-
1. Useawebbrowsertogoto `http://localhost:5000`. You'll notice that the font color is black.
72
+
Use a web browser to go to `http://localhost:5000`. You'll notice that the font color is black.
75
73
76
74

77
75
78
-
1. Update `launchSettings.json` tosetthe `ASPNETCORE_ENVIRONMENT` variableto `Development`. Run `dotnetrun` again.
76
+
Update `launchSettings.json` to set the `ASPNETCORE_ENVIRONMENT` variable to `Development`. Run `dotnet run` again.
79
77
80
78
You'll notice that the font color is now red. This is because the application now uses the value of `TestApp:Settings:FontColor` that has the `Development` label. All other configuration values remain the same as their production values.
0 commit comments