I'm on a new ASP.NET 5 project.
I'm trying to read an array value, stored in my config.json
file, that looks like this:
{
"AppSettings": {
"SiteTitle": "MyProject",
"Tenants": {
"ReservedSubdomains": ["www", "info", "admin"]
}
},
"Data": {
"DefaultConnection": {
"ConnectionString": "Server=(localdb)\\mssqllocaldb;Database=aspnet5-MyProject....."
}
}
}
How do I access this from my C# code?
At least with beta4 arrays aren't supported in
config.json
. See ASP.NET issue 620. But you could use the followingconfig.json
:and map it to a class like this:
This can then be injected into a controller: