2

I have an ActionFilter that does logging. I want this to log requests and parameters that come in to the server. This works fine. However when I add OutputCaching, this will only log the first request and no others.

I even tried creating an ActionFilter that behaves as such:

public class OutputCacheLoggingFilterAttribute : OutputCacheAttribute
{     
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        //Do my stuff

        base.OnActionExecuting(filterContext);
    }
}

I figured if I inherited from the outputcache that it would HAVE to run my code before it would get to the base call. Yet I was proven wrong and somehow my code will only execute once.

Chris Marisic
  • 32,487
  • 24
  • 164
  • 258

1 Answers1

0

Well, as far as i know, there is "a hack" in this system which ensures that authorization attributes are executed every time, regardless caching. Maybe you can make your filter implement IAuthorizationFilter and do your work in OnAuthorization method. Yes, it is a nasty trick, but still better than "hacking" caching system itself, i think.

Let us know if it works (i never tested it, just a first idea in my head :)

rouen
  • 5,003
  • 2
  • 25
  • 48
  • Now that's an interesting solution. Although isn't the downside to this doesn't the authorization attribute have the only 1 allowed per action thing set on it? – Chris Marisic Sep 14 '11 at 12:29
  • No, afaik you can use any number of authorization attributes on action. – rouen Oct 04 '11 at 06:46