سؤال

I am using the OutputCache attribute to cache my home page content

[OutputCache(CacheProfile = "Default")]
public ActionResult Index()
{
     .....
}

I also have a custom global attribute set-up that checks each request for a valid browser type

GlobalFilters.Filters.Add(new BadBrowserAttribute());

The OnActionExecuting fires as needed during the first request, but not again until the cache expires.

I had thought the Order value of the attributes may help but it doesn't seem to have made any difference.

Is it possible to get my custom attribute to fire every time for cached content?

هل كانت مفيدة؟

المحلول

It's impossible for your action to fire everytime. When you use caching (as in your code), on subsequent request results will be returned from cache, so action won't be executed.

A workoround might be to implement custom caching inside your action filter. Something like this

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top