From 8de6090b827ce3fa5b84378885767f446476656b Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Wed, 11 Feb 2026 08:53:06 -0500 Subject: [PATCH 1/6] Update the 'Bind an array' section --- .../fundamentals/configuration/index.md | 187 ++++-------------- 1 file changed, 42 insertions(+), 145 deletions(-) diff --git a/aspnetcore/fundamentals/configuration/index.md b/aspnetcore/fundamentals/configuration/index.md index e9d5ec51b827..81b9bc92d495 100644 --- a/aspnetcore/fundamentals/configuration/index.md +++ b/aspnetcore/fundamentals/configuration/index.md @@ -1063,8 +1063,6 @@ Host.CreateDefaultBuilder(args) ::: moniker-end -For an additional example that uses a , see the [Bind an array](#bind-an-array) section. - ## Kestrel endpoint configuration Kestrel-specific endpoint configuration overrides all [cross-server](xref:fundamentals/servers/index) endpoint configurations. Cross-server endpoint configurations include: @@ -1230,7 +1228,7 @@ The extension method: +`value3.json`: -```csharp -public class Program +```json { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) - { - var arrayDict = new Dictionary - { - {"array:entries:0", "value0"}, - {"array:entries:1", "value1"}, - {"array:entries:2", "value2"}, - // 3 Skipped - {"array:entries:4", "value4"}, - {"array:entries:5", "value5"} - }; - - return Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration((hostingContext, config) => - { - config.AddInMemoryCollection(arrayDict); - }) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + "array:entries:3": "value30" } ``` -The following code reads the configuration in the `arrayDict` `Dictionary` and displays the values: +::: moniker range=">= aspnetcore-6.0" ```csharp -public class ArrayModel : PageModel +var configSettings = new Dictionary { - private readonly IConfiguration Config; - public ArrayExample _array { get; private set; } - - public ArrayModel(IConfiguration config) - { - Config = config; - } - - public ContentResult OnGet() - { - _array = Config.GetSection("array").Get(); - string s = null; - - for (int j = 0; j < _array.Entries.Length; j++) - { - s += $"Index: {j} Value: {_array.Entries[j]} \n"; - } - - return Content(s); - } -} -``` - -The preceding code returns the following output: + { "array:entries:0", "value00" }, + { "array:entries:1", "value10" }, + { "array:entries:2", "value20" }, + { "array:entries:4", "value40" }, + { "array:entries:5", "value50" } +}; -```text -Index: 0 Value: value0 -Index: 1 Value: value1 -Index: 2 Value: value2 -Index: 3 Value: value4 -Index: 4 Value: value5 +builder.Configuration.AddInMemoryCollection(configSettings); +builder.Configuration.AddJsonFile("value3.json", optional: false, + reloadOnChange: false); ``` -Index #3 in the bound object holds the configuration data for the `array:4` configuration key and its value of `value4`. When configuration data containing an array is bound, the array indices in the configuration keys are used to iterate the configuration data when creating the object. A null value can't be retained in configuration data, and a null-valued entry isn't created in a bound object when an array in configuration keys skip one or more indices. - -The missing configuration item for index #3 can be supplied before binding to the `ArrayExample` instance by any configuration provider that reads the index #3 key/value pair. Consider the following `Value3.json` file from the sample download: - -```json -{ - "array:entries:3": "value3" -} -``` +::: moniker-end -The following code includes configuration for `Value3.json` and the `arrayDict` `Dictionary`: +::: moniker range="< aspnetcore-6.0" ```csharp -public class Program -{ - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) +Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => { - var arrayDict = new Dictionary + webBuilder.UseStartup(); + }) + .ConfigureAppConfiguration(config => + { + var configSettings = new Dictionary { - {"array:entries:0", "value0"}, - {"array:entries:1", "value1"}, - {"array:entries:2", "value2"}, - // 3 Skipped - {"array:entries:4", "value4"}, - {"array:entries:5", "value5"} + { "array:entries:0", "value00" }, + { "array:entries:1", "value10" }, + { "array:entries:2", "value20" }, + { "array:entries:4", "value40" }, + { "array:entries:5", "value50" } }; - return Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration((hostingContext, config) => - { - config.AddInMemoryCollection(arrayDict); - config.AddJsonFile("Value3.json", - optional: false, reloadOnChange: false); - }) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } -} + config.AddInMemoryCollection(configSettings); + config.AddJsonFile("value3.json", optional: false, reloadOnChange: false); + }); ``` -The following code reads the preceding configuration and displays the values: - -```csharp -public class ArrayModel : PageModel -{ - private readonly IConfiguration Config; - public ArrayExample _array { get; private set; } - - public ArrayModel(IConfiguration config) - { - Config = config; - } - - public ContentResult OnGet() - { - _array = Config.GetSection("array").Get(); - string s = null; - - for (int j = 0; j < _array.Entries.Length; j++) - { - s += $"Index: {j} Value: {_array.Entries[j]} \n"; - } - - return Content(s); - } -} -``` +:::moniker-end -The preceding code returns the following output: +The preceding code results in the following configuration key/value pairs: -```text -Index: 0 Value: value0 -Index: 1 Value: value1 -Index: 2 Value: value2 -Index: 3 Value: value3 -Index: 4 Value: value4 -Index: 5 Value: value5 +```console +Index: 0 Value: value00 +Index: 1 Value: value10 +Index: 2 Value: value20 +Index: 3 Value: value30 +Index: 3 Value: value40 +Index: 4 Value: value50 ``` -Custom configuration providers aren't required to implement array binding. - -:::moniker-end - ## Custom configuration provider The sample app demonstrates how to create a basic configuration provider that reads configuration key-value pairs from a database using [Entity Framework (EF)](/ef/core/). From 11fd35ebe17ca48bf6486b8695df3a8d07d8aa0b Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Wed, 11 Feb 2026 08:57:43 -0500 Subject: [PATCH 2/6] Updates --- aspnetcore/fundamentals/configuration/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/fundamentals/configuration/index.md b/aspnetcore/fundamentals/configuration/index.md index 81b9bc92d495..33f248d6a309 100644 --- a/aspnetcore/fundamentals/configuration/index.md +++ b/aspnetcore/fundamentals/configuration/index.md @@ -1265,7 +1265,7 @@ Index: 4 Value: value50 In the preceding output, Index 3 has value `value40`, corresponding to `"4": "value40",` in `array.json`. The bound array indices are continuous and not bound to the configuration key index. The configuration binder isn't capable of binding `null` values or creating `null` entries in bound objects. -The missing configuration item for Index 3 can be supplied by any configuration provider that reads an Index 3 key/value pair. In the following example, assume that the values provided by `array.json` in the preceding example are provided by an [in-memory collection](#memory-configuration-provider). The example shows how to load the Index 3 value from the [JSON Configuration Provider](#json-configuration-provider). +The missing configuration item for Index 3 can be supplied before binding to the `ArrayExample` instance by any configuration provider that reads the Index 3 key/value pair. In the following example, assume that the values provided by `array.json` in the preceding example are provided by an [in-memory collection](#memory-configuration-provider). The example shows how to load the Index 3 value from the [JSON Configuration Provider](#json-configuration-provider) before the collection is bound. `value3.json`: From f4480438482b73a3f9c31a28936ffc8342b75619 Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Wed, 11 Feb 2026 09:06:08 -0500 Subject: [PATCH 3/6] Updates --- aspnetcore/fundamentals/configuration/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/fundamentals/configuration/index.md b/aspnetcore/fundamentals/configuration/index.md index 33f248d6a309..e28b0500361d 100644 --- a/aspnetcore/fundamentals/configuration/index.md +++ b/aspnetcore/fundamentals/configuration/index.md @@ -5,7 +5,7 @@ description: Learn how to use the Configuration API to configure app settings in monikerRange: '>= aspnetcore-3.1' ms.author: tdykstra ms.custom: mvc -ms.date: 01/23/2026 +ms.date: 02/11/2026 uid: fundamentals/configuration/index --- # Configuration in ASP.NET Core From 03a5c383b7ac4fb71bd2b4e2c5dd1193fae4d357 Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Wed, 11 Feb 2026 09:06:48 -0500 Subject: [PATCH 4/6] Updates --- aspnetcore/fundamentals/configuration/index.md | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/aspnetcore/fundamentals/configuration/index.md b/aspnetcore/fundamentals/configuration/index.md index e28b0500361d..e824172d3e53 100644 --- a/aspnetcore/fundamentals/configuration/index.md +++ b/aspnetcore/fundamentals/configuration/index.md @@ -10,23 +10,6 @@ uid: fundamentals/configuration/index --- # Configuration in ASP.NET Core - - [!INCLUDE[](~/includes/not-latest-version.md)] App configuration in ASP.NET Core is performed using one or more [configuration providers](#configuration-providers). Configuration providers read configuration data from key-value pairs using a variety of configuration sources: From 10e10d7ab57d2e027c3ad07b3f1e8a5678a7aaa0 Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Wed, 11 Feb 2026 09:10:00 -0500 Subject: [PATCH 5/6] Updates --- aspnetcore/fundamentals/configuration/index.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/aspnetcore/fundamentals/configuration/index.md b/aspnetcore/fundamentals/configuration/index.md index e824172d3e53..e28b0500361d 100644 --- a/aspnetcore/fundamentals/configuration/index.md +++ b/aspnetcore/fundamentals/configuration/index.md @@ -10,6 +10,23 @@ uid: fundamentals/configuration/index --- # Configuration in ASP.NET Core + + [!INCLUDE[](~/includes/not-latest-version.md)] App configuration in ASP.NET Core is performed using one or more [configuration providers](#configuration-providers). Configuration providers read configuration data from key-value pairs using a variety of configuration sources: From e127aba6da139d5da1fbb9678ea07af12d5f1434 Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Wed, 11 Feb 2026 09:13:33 -0500 Subject: [PATCH 6/6] Updates --- aspnetcore/fundamentals/configuration/index.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/aspnetcore/fundamentals/configuration/index.md b/aspnetcore/fundamentals/configuration/index.md index e28b0500361d..564fb01bf99f 100644 --- a/aspnetcore/fundamentals/configuration/index.md +++ b/aspnetcore/fundamentals/configuration/index.md @@ -1,5 +1,6 @@ --- title: Configuration in ASP.NET Core +ai-usage: ai-assisted author: tdykstra description: Learn how to use the Configuration API to configure app settings in an ASP.NET Core app. monikerRange: '>= aspnetcore-3.1' @@ -1320,15 +1321,15 @@ Host.CreateDefaultBuilder(args) :::moniker-end -The preceding code results in the following configuration key/value pairs: +The preceding code results in the following bound array: ```console Index: 0 Value: value00 Index: 1 Value: value10 Index: 2 Value: value20 Index: 3 Value: value30 -Index: 3 Value: value40 -Index: 4 Value: value50 +Index: 4 Value: value40 +Index: 5 Value: value50 ``` ## Custom configuration provider