How can I check if a specific section in loaded ASP.NET Core configuration file exist?
I have a JSON configuration file that I load it in Startup
class via ConfigurationBuilder.AddJsonFile
method.
This JSON file is an array with this layout:
{
"Url": "",
"Regex": [ "", "" ],
"Keys": {
"Title": "",
"Description": "",
"Keywords": [ "" ]
}
}
But some of them doesn't have Keys
. I tried to check return type of section.GetSection("Keys")
against null
, But it doesn't return null
even if Keys
section isn't present.
Use GetChildren
method:
var keysExists = Configuration.GetChildren().Any(x => x.Key == "Keys"));
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加