【发布时间】:2015-08-07 09:53:51
【问题描述】:
我希望能够在我的 config.json 文件中编辑缓存配置文件设置。您可以在 ASP.NET 4.6 中使用 web.config 文件执行类似的操作。这就是我现在拥有的:
services.ConfigureMvc(
mvcOptions =>
{
mvcOptions.CacheProfiles.Add(
"RobotsText",
new CacheProfile()
{
Duration = 86400,
Location = ResponseCacheLocation.Any,
// VaryByParam = "none" // Does not exist in MVC 6 yet.
});
});
我想做这样的事情:
services.ConfigureMvc(
mvcOptions =>
{
var cacheProfiles = ConfigurationBinder.Bind<Dictionary<string, CacheProfile>>(
Configuration.GetConfigurationSection("CacheProfiles"));
foreach (var keyValuePair in cacheProfiles)
{
mvcOptions.CacheProfiles.Add(keyValuePair);
}
});
我的appsettings.json 文件看起来像这样:
{
"AppSettings": {
"SiteTitle": "ASP.NET MVC Boilerplate"
}
"CacheProfiles" : {
"RobotsText" : {
"Duration" : 86400,
"Location" : "Any",
}
}
}
但是,我无法让它工作。尝试绑定配置部分时,我不断收到反射错误。
【问题讨论】:
标签: asp.net-core asp.net-core-mvc