I\'m trying to use cache profiles for caching child actions in my mvc application, but I get an exception: Duration must be a positive number.
My web.config looks li
I got around the problem by creating a custom OutputCache attribute, that manually loads the Duration, VarByCustom and VarByParam from the profile:
public class ChildActionOutputCacheAttribute : OutputCacheAttribute
{
public ChildActionOutputCacheAttribute(string cacheProfile)
{
var settings = (OutputCacheSettingsSection)WebConfigurationManager.GetSection("system.web/caching/outputCacheSettings");
var profile = settings.OutputCacheProfiles[cacheProfile];
Duration = profile.Duration;
VaryByParam = profile.VaryByParam;
VaryByCustom = profile.VaryByCustom;
}
}
The advantage of this approach is that you get to still keep all your profiles in just one place in the web.config.