Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 207
Zac Seth Avatar asked Nov 13 '08 22:11

Zac Seth


People also ask

What is the use of output cache attribute in MVC?

The output cache enables you to cache the content returned by a controller action. That way, the same content does not need to be generated each and every time the same controller action is invoked. Imagine, for example, that your ASP.NET MVC application displays a list of database records in a view named Index.

What is the property used to set the output cache timeout value in ASP.NET MVC?

The OutputCache Attribute in ASP.NET MVC Application is used to cache the content returned by a controller action method for a specific time period, so that, if the subsequent request comes within that time period, then the content is going to be returned from the cache memory.

Which of the following properties of OutputCache attribute can be used to control customize the caching?

By default, when you use the [OutputCache] attribute, content is cached in three locations: the web server, any proxy servers, and the web browser. You can control exactly where content is cached by modifying the Location property of the [OutputCache] attribute. By default, the Location property has the value Any.

Which output cache is stored on the server where the request was processed?

The output cache is located on the Web server where the request was processed. This value corresponds to the Server enumeration value. The output cache can be stored only at the origin server or at the requesting client. Proxy servers are not allowed to cache the response.


1 Answers

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

like image 133
Zac Seth Avatar answered Sep 27 '22 18:09

Zac Seth