asp.net-mvcoutputcache

ASP.Net MVC Output Caching: The directive or the configuration settings profile must specify the 'varyByParam' attribute


I encountered the above error message after applying the OutputCache attribute on ActionResult methods with no input parameters - why would I use VaryByParams in this case? Is this a bug in ASP.Net MVC or is there a way of using OutputCache without setting this property?

My big question is, if I have to use VaryByParams, what should I enter for a value if I have no parameters to cache against?


Solution

  • I never found a satisfactory answer for this - basically, you just need to add the VaryByParams property and if you don't have any parameters set it to the magic string "none".

    http://msdn.microsoft.com/en-us/library/system.web.ui.outputcacheparameters.varybyparam.aspx