How to check if Configuration Section exists in .NET Core?
问题 How can you check if a configuration section exists in the appsettings.json in .NET Core? Even if a section doesn't exist, the following code will always return an instantiated instance. e.g. var section = this.Configuration.GetSection<TestSection>("testsection"); 回答1: 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,