2

I want to apply a filter before the OutputCache is applied.

I have this controller annotation

[OutputCache(Duration=3600,VaryByCustom="TypeOfDevice", Order=10)]
public ActionResult Index()
    

I defined the GetVaryByCustom method in Global.asax .

Also, I apply a filter of type ActionFilterAttribute in Global.asax

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        // Register track filter
        GlobalFilters.Filters.Add(new FrontEnd.Filters.MyFilter(), 0);

The first time MyFilter is executed, but the following request do not reach the filter and the response comes from the OutputCache.

How could I apply the MyFilter before the OutputCache.

Thanks in advance

Update:

MyFilter is an ActionFilterAttribute with the method override

 public override void OnActionExecuting(ActionExecutingContext context)
 {
    // SET A COOKIE

    base.OnActionExecuting(context);
 }
Community
  • 1
  • 1
Jonathan Barbero
  • 2,504
  • 1
  • 26
  • 47
  • You might find a hint and/or an explanation in this thread, [SO-10990337](http://stackoverflow.com/questions/10990337/working-with-the-output-cache-and-other-action-filters). Let me know either way. – CrnaStena May 06 '15 at 00:18
  • It would be helpful to see the definition of MyFilter. Are you overriding OnActionExecuting or OnResultExecuting or are you even deriving from ActionFilterAttribute? – rism May 06 '15 at 06:09
  • @CrnaStena I would prefer to not use DonutOutputCache because it's not the standard way to do the caching. I prefer to stay with the official MVC way. I tried to override OnResultExecuting in MyFilter, maybe it would be called like with Donut as the link explain, but not. – Jonathan Barbero May 06 '15 at 15:44

1 Answers1

0

Perhaps you could inherit from OutputCacheAttribute and override OnResultExecuting