MVC HTML.RenderAction – Error: Duration must be a positive number

后端 未结 4 1713
没有蜡笔的小新
没有蜡笔的小新 2021-02-13 04:27

On my website I want the user to have the ability to login/logout from any page. When the user select login button a modal dialog will be present to the user for him to enter i

4条回答
  •  忘了有多久
    2021-02-13 05:16

    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.

    This is also posted in the related question: https://stackoverflow.com/a/13866280/1373170

提交回复
热议问题