How to check if Configuration Section exists in .NET Core?

Query the children of Configuration and check if there is any with the name "testsection"

var sectionExists = Configuration.GetChildren().Any(item => item.Key == "testsection"));

This should return true if "testsection" exists, otherwise false.


Since .NET Core 2.0, you can also call the ConfigurationExtensions.Exists extension method to check if a section exists.

var section = this.Configuration.GetSection("testsection");
var sectionExists = section.Exists();

Since GetSection(sectionKey) never returns null, you can safely call Exists on its return value.

It is also helpful to read this documentation on Configuration in ASP.NET Core.