开发者

How can I Override OutputCache from basecontroller in action?

I have a basecontroller that makes sure pages expire so the back button will display a Web开发者_Python百科page 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?


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

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

Does the job..


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜