Question

I have a basecontroller that makes sure pages expire so the back button will display a Webpage has expired. This is done like so: [OutputCache(NoStore = true, Duration = 0, VaryByParam = "none")]

However i want to have the default behavious where I can navigate back from one action on a controller that inherits from the base. It seems like no matter what a set the OutputCache attribute to on the action it still displays "Webpage has expired". Any ideas now I can get it to cache on this one action?

Was it helpful?

Solution

Found a way around it by handeling when the nostore header without using the outputcache attributes

HttpContext.Current.Response.Cache.SetNoStore();

Does the job..

OTHER TIPS

Apparently you can set the [OutputCache] attribute on a method in the derived class, and this will override the attribute on the base class.

[OutputCache(NoStore = true, 
             Duration = 0, 
             VaryByParam = "*")]
public abstract class BaseController : Controller
{ 
    // no cache by default
}

public class MyController : BaseController
{
    [OutputCache(NoStore = false, 
                 Duration = 60, 
                 VaryByParam = "searchText", 
                 Location = OutputCacheLocation.Any)]
    public PartialViewResult Test(string searchText)
    {
        // this method cached ok
    }        
}

From testing, this seems to work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top