I have an MVC .Net application that has actions that return report files, usually .xslx
:
byte[] data = GetReport();
return File(data,
\"applica
I've come up with a workaround, but it's a definite hack - this is a new cache attribute to replace the built-in [OutputCache]
one:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public sealed class IENoCacheAttribute : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
if (filterContext.HttpContext.Request.IsSecureConnection &&
string.Equals(filterContext.HttpContext.Request.Browser.Browser, "IE", StringComparison.OrdinalIgnoreCase) &&
filterContext.HttpContext.Request.Browser.MajorVersion < 9)
{
filterContext.HttpContext.Response.ClearHeaders();
filterContext.HttpContext.Response.AddHeader("cache-control", "no-store, no-cache, must-revalidate");
}
else
{
filterContext.HttpContext.Response.Cache.SetNoStore();
filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
}
base.OnResultExecuting(filterContext);
}
}
It's a workaround at best though - what I really want is to extend the existing [OutputCache]
and Response.Cache
structures so that they have the desired output suitable for legacy IEs.