Чтобы отключить кеш браузера, чтобы надежно указать браузеру не кэшировать, я обнаружил, что лучшим решением было создать собственный класс атрибутов [NoCache].
public class NoCacheSettingsAttribute : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
filterContext.HttpContext.Response.Cache.SetNoStore();
base.OnResultExecuting(filterContext);
}
}
И глобальные настройки фильтра
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
// Makes sure that cached pages are not served to any browser including chrome
filters.Add(new NoCacheSettingsAttribute());
}
Я хочу использовать [OutputCache(CacheProfile = "2Hour")]
в некотором ActionResult контроллера, а также хочу использовать NoCacheSetting для остальной части контроллера глобально, скажем, в BaseController, ( все контроллеры наследуются от BaseController)
Так что вопрос в том, будет ли он нормально работать? Или я должен поставить остальные контроллеры 1 на один?