Toran Billups
Toran Billups

Reputation: 27399

How to tell MVC not to cache an aspx or ascx?

In webforms I would do something like this in the OnInit method, but where (and how) could I do the same type of thing using MVC?

Response.Cache.SetCacheability(HttpCacheability.NoCache)

Upvotes: 0

Views: 934

Answers (2)

tvanfosson
tvanfosson

Reputation: 532455

Do you mean a non-MVC page in an MVC application, then the same way. If you mean a particular action corresponding to a view, then use the OutputCacheAttribute on the action or controller with Location = OutputCacheLocation.None.

Upvotes: 1

Mehrdad Afshari
Mehrdad Afshari

Reputation: 421988

You can do the exact same thing in MVC too in the controller action (by writing the same line of code) or adding an attribute (which is preferred):

[OutputCache(Location=System.Web.UI.OutputCacheLocation.None)]
public ActionResult Index() {
   // ...
}

Upvotes: 3

Related Questions