Monday, April 25, 2011

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?

From stackoverflow
  • 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

    bzlm : Not an empty string. According to MSDN, if no parameters are to be used, the value of VaryByParam should be "none": http://msdn.microsoft.com/en-us/library/system.web.ui.outputcacheparameters.varybyparam.aspx
    Zac : Ah, that's useful to know - I guess that's the problem with good ol' magic strings eh?

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.