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/enable-dynamic-configuration-aspnet-core.md
+42-33Lines changed: 42 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,11 +21,11 @@ ms.custom: mvc
21
21
---
22
22
# Tutorial: Use dynamic configuration in an ASP.NET Core app
23
23
24
-
ASP.NET Core has a pluggable configuration system that can read configuration data from a variety of sources. It can handle changes on the fly without causing an application to restart. ASP.NET Core supports the binding of configuration settings to strongly typed .NET classes. It injects them into your code by using the various `IOptions<T>` patterns. One of these patterns, specifically `IOptionsSnapshot<T>`, automatically reloads the application's configuration when the underlying data changes. You can inject `IOptionsSnapshot<T>` into controllers in your application to access the most recent configuration stored in Azure App Configuration.
24
+
ASP.NET Core has a pluggable configuration system that can read configuration data from a variety of sources. It can handle changes dynamically without causing an application to restart. ASP.NET Core supports the binding of configuration settings to strongly typed .NET classes. It injects them into your code by using the various `IOptions<T>` patterns. One of these patterns, specifically `IOptionsSnapshot<T>`, automatically reloads the application's configuration when the underlying data changes. You can inject `IOptionsSnapshot<T>` into controllers in your application to access the most recent configuration stored in Azure App Configuration.
25
25
26
-
You also can set up the App Configuration ASP.NET Core client library to refresh a set of configuration settings dynamically using a middleware. As long as the web app continues to receive requests, the configuration settings continue to get updated with the configuration store.
26
+
You also can set up the App Configuration ASP.NET Core client library to refresh a set of configuration settings dynamically using a middleware. The configuration settings get updated with the configuration store each time as long as the web app receives requests.
27
27
28
-
In order to keep the settings updated and avoid too many calls to the configuration store, a cache is used for each setting. Until the cached value of a setting has expired, the refresh operation does not update the value, even when the value has changed in the configuration store. The default expiration time for each request is 30 seconds, but it can be overridden if required.
28
+
App Configuration automatically caches each setting to avoid too many calls to the configuration store. The refresh operation waits until the cached value of a setting expires to update that setting, even when its value changes in the configuration store. The default cache expiration time is 30 seconds. You can override this expiration time, if necessary.
29
29
30
30
This tutorial shows how you can implement dynamic configuration updates in your code. It builds on the web app introduced in the quickstarts. Before you continue, finish [Create an ASP.NET Core app with App Configuration](./quickstart-aspnet-core-app.md) first.
31
31
@@ -45,6 +45,16 @@ To do this tutorial, install the [.NET Core SDK](https://dotnet.microsoft.com/do
45
45
46
46
Before you continue, finish [Create an ASP.NET Core app with App Configuration](./quickstart-aspnet-core-app.md) first.
47
47
48
+
## Add a sentinel key
49
+
50
+
A *sentinel key* is a special key used to signal when configuration has changed. Your app monitors the sentinel key for changes. When a change is detected, you refresh all configuration values. This approach reduces the overall number of requests made by your app to App Configuration, compared to monitoring all keys for changes.
51
+
52
+
1. In the Azure portal, select **Configuration Explorer > Create > Key-value**.
53
+
54
+
1. For **Key**, enter *TestApp:Settings:Sentinel*. For **Value**, enter 1. Leave **Label** and **Content type** blank.
55
+
56
+
1. Select **Apply**.
57
+
48
58
## Reload data from App Configuration
49
59
50
60
1. Add a reference to the `Microsoft.Azure.AppConfiguration.AspNetCore` NuGet package by running the following command:
@@ -68,11 +78,10 @@ Before you continue, finish [Create an ASP.NET Core app with App Configuration](
The `ConfigureRefresh` method is used to specify the settings used to update the configuration data with the App Configuration store when a refresh operation is triggered. In order to actually trigger a refresh operation, a refresh middleware needs to be configured for the application to refresh the configuration data when any change occurs.
113
+
The `ConfigureRefresh` method is used to specify the settings used to update the configuration data with the App Configuration store when a refresh operation is triggered. The `refreshAll` parameter to the `Register` method indicates that all configuration values should be refreshed if the sentinel key changes.
114
+
115
+
Also, the `SetCacheExpiration` method overrides the default cache expiration time of 30 seconds, specifying a time of 5 minutes instead. This reduces the number of requests made to App Configuration.
116
+
117
+
> [!NOTE]
118
+
> For testing purposes, you may want to lower the cache expiration time.
119
+
120
+
To actually trigger a refresh operation, you'll need to configure a refresh middleware for the application to refresh the configuration data when any change occurs. You'll see how to do this in a later step.
106
121
107
122
2. Add a *Settings.cs* file that defines and implements a new `Settings` class.
108
123
@@ -199,10 +214,7 @@ Before you continue, finish [Create an ASP.NET Core app with App Configuration](
199
214
```
200
215
---
201
216
202
-
The middleware uses the refresh configuration specified in the `AddAzureAppConfiguration` method in `Program.cs` to trigger a refresh for each request received by the ASP.NET Core web app. For each request, a refresh operation is triggered and the client library checks if the cached value for the registered configuration settings have expired. For the cached values that have expired, the values for the settings are updated with the App Configuration store, and the remaining values remain unchanged.
203
-
204
-
> [!NOTE]
205
-
> The default cache expiration time for a configuration setting is 30 seconds, but can be overridden by calling the `SetCacheExpiration` method on the options initializer passed as an argument to the `ConfigureRefresh` method.
217
+
The middleware uses the refresh configuration specified in the `AddAzureAppConfiguration` method in `Program.cs` to trigger a refresh for each request received by the ASP.NET Core web app. For each request, a refresh operation is triggered and the client library checks if the cached value for the registered configuration setting has expired. If it's expired, it's refreshed.
206
218
207
219
## Use the latest configuration data
208
220
@@ -279,7 +291,7 @@ Before you continue, finish [Create an ASP.NET Core app with App Configuration](
279
291
}
280
292
h1 {
281
293
color: @ViewData["FontColor"];
282
-
font-size: @ViewData["FontSize"];
294
+
font-size: @ViewData["FontSize"]px;
283
295
}
284
296
</style>
285
297
<head>
@@ -297,38 +309,35 @@ Before you continue, finish [Create an ASP.NET Core app with App Configuration](
297
309
298
310
dotnet build
299
311
300
-
2. After the build successfully completes, run the following command to run the web app locally:
312
+
1. After the build successfully completes, run the following command to run the web app locally:
301
313
302
314
dotnet run
315
+
1. Open a browser window, and go to the URL shown in the `dotnet run` output.
303
316
304
-
3. Open a browser window, and go to `http://localhost:5000`, which is the default URL for the web app hosted locally.
4. Sign in to the [Azure portal](https://portal.azure.com). Select **All resources**, and select the App Configuration store instance that you created in the quickstart.
319
+
1. Sign in to the [Azure portal](https://portal.azure.com). Select **All resources**, and select the App Configuration store instance that you created in the quickstart.
309
320
310
-
5. Select **Configuration Explorer**, and update the values of the following keys:
321
+
1. Select **Configuration Explorer**, and update the values of the following keys:
311
322
312
323
| Key | Value |
313
324
|---|---|
314
325
| TestApp:Settings:BackgroundColor | green |
315
326
| TestApp:Settings:FontColor | lightGray |
316
327
| TestApp:Settings:Message | Data from Azure App Configuration - now with live updates! |
328
+
| TestApp:Settings:Sentinel | 2 |
317
329
318
-
6. Refresh the browser page to see the new configuration settings. More than one refresh of the browser page may be required for the changes to be reflected.
330
+
1. Refresh the browser page to see the new configuration settings. You may need to refresh more than once for the changes to be reflected.
> Since the configuration settings are cached with a default expiration time of 30 seconds, any changes made to the settings in the App Configuration store would only be reflected in the web app when the cache has expired.
In this tutorial, you enabled your ASP.NET Core web app to dynamically refresh configuration settings from App Configuration. To learn how to use an Azuremanaged identity to streamline the access to App Configuration, continue to the next tutorial.
340
+
In this tutorial, you enabled your ASP.NET Core web app to dynamically refresh configuration settings from App Configuration. To learn how to use an Azure-managed identity to streamline the access to App Configuration, continue to the next tutorial.
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/faq.md
+20-1Lines changed: 20 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,7 +63,7 @@ See [best practices](./howto-best-practices.md).
63
63
64
64
## How much does App Configuration cost?
65
65
66
-
There are two pricing tiers:
66
+
There are two pricing tiers:
67
67
68
68
- Free tier
69
69
- Standard tier.
@@ -95,6 +95,25 @@ You can upgrade from the Free tier to the Standard tier at any time.
95
95
96
96
You can't downgrade a store from the Standard tier to the Free tier. You can create a new store in the Free tier and then [import configuration data into that store](howto-import-export-data.md).
97
97
98
+
## Are there any limits on the number of requests made to App Configuration?
99
+
100
+
Configuration stores in the Free tier are limited to 1,000 requests per day. Configuration stores in the Standard tier may experience temporary throttling when the request rate exceeds 20,000 requests per hour.
101
+
102
+
When a store reaches its limit, it will return HTTP status code 429 for all requests made until the time period expires. The `retry-after-ms` header in the response gives a suggested wait time (in milliseconds) before retrying the request.
103
+
104
+
If your application regularly experiences HTTP status code 429 responses, consider redesigning it to reduce the number of requests made. For more information, see [Reduce requests made to App Configuration](./howto-best-practices.md#reduce-requests-made-to-app-configuration)
105
+
106
+
## My application receives HTTP status code 429 responses. Why?
107
+
108
+
You'll receive an HTTP status code 429 response under these circumstances:
109
+
110
+
* Exceeding the daily request limit for a store in the Free tier.
111
+
* Temporary throttling due to a high request rate for a store in the Standard tier.
112
+
* Excessive bandwidth usage.
113
+
* Attempting to create or modify a key when the storage quote is exceeded.
114
+
115
+
Check the body of the 429 response for the specific reason why the request failed.
116
+
98
117
## How can I receive announcements on new releases and other information related to App Configuration?
99
118
100
119
Subscribe to our [GitHub announcements repo](https://github.com/Azure/AppConfiguration-Announcements).
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/howto-best-practices.md
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,9 +69,19 @@ You can provide access to App Configuration for web apps or functions by using a
69
69
* Use Azure managed identities to access the App Configuration store. For more information, see [Integrate with Azure managed identities](howto-integrate-azure-managed-service-identity.md).
70
70
* Push configuration from App Configuration to App Service. App Configuration provides an export function (in Azure portal and the Azure CLI) that sends data directly into App Service. With this method, you don't need to change the application code at all.
71
71
72
+
## Reduce requests made to App Configuration
73
+
74
+
Excessive requests to App Configuration can result in throttling or overage charges. To reduce the number of requests made:
75
+
76
+
* Increase the refresh timeout, especially if your configuration values do not change frequently. Specify a new refresh timeout using the [`SetCacheExpiration` method](/dotnet/api/microsoft.extensions.configuration.azureappconfiguration.azureappconfigurationrefreshoptions.setcacheexpiration).
77
+
78
+
* Watch a single *sentinel key*, rather than watching individual keys. Refresh all configuration only if the sentinel key changes. See [Use dynamic configuration in an ASP.NET Core app](enable-dynamic-configuration-aspnet-core.md) for an example.
79
+
80
+
* Use Azure Event Grid to receive notifications when configuration changes, rather than constantly polling for any changes. See [Route Azure App Configuration events to a web endpoint](./howto-app-configuration-event.md) for more information
81
+
72
82
## Importing configuration data into App Configuration
73
83
74
-
App Configuration offers the option to bulk [import](https://aka.ms/azconfig-importexport1) your configuration settings from your current configuration files using either the Azure Portal or CLI. You can also use the same options to export values from App Configuration, for example between related stores. If you’d like to set up an ongoing sync with your GitHub repo, you can use our [GitHub Action](https://aka.ms/azconfig-gha2) so that you can continue using your existing source control practices while getting the benefits of App Configuration.
84
+
App Configuration offers the option to bulk [import](https://aka.ms/azconfig-importexport1) your configuration settings from your current configuration files using either the Azure portal or CLI. You can also use the same options to export values from App Configuration, for example between related stores. If you’d like to set up an ongoing sync with your GitHub repo, you can use our [GitHub Action](https://aka.ms/azconfig-gha2) so that you can continue using your existing source control practices while getting the benefits of App Configuration.
0 commit comments