I would like to be able to edit the cache profile settings in my config.json file. You could do something similar in ASP.NET 4.6 with the web.config file. This is what I have now:
services.ConfigureMvc(
mvcOptions =>
{
mvcOptions.CacheProfiles.Add(
"RobotsText",
new CacheProfile()
{
Duration = 86400,
Location = ResponseCacheLocation.Any,
// VaryByParam = "none" // Does not exist in MVC 6 yet.
});
});
I would like to do something like this:
services.ConfigureMvc(
mvcOptions =>
{
var cacheProfiles = ConfigurationBinder.Bind<Dictionary<string, CacheProfile>>(
Configuration.GetConfigurationSection("CacheProfiles"));
foreach (var keyValuePair in cacheProfiles)
{
mvcOptions.CacheProfiles.Add(keyValuePair);
}
});
With my appsettings.json
file looking like this:
{
"AppSettings": {
"SiteTitle": "ASP.NET MVC Boilerplate"
}
"CacheProfiles" : {
"RobotsText" : {
"Duration" : 86400,
"Location" : "Any",
}
}
}
However, I have not been able to get this to work. I keep getting reflection errors upon trying to bind the configuration section.