IE6-8 unable to download file from HTTPS site

后端 未结 2 977
滥情空心
滥情空心 2021-02-14 19:06

I have an MVC .Net application that has actions that return report files, usually .xslx:

byte[] data = GetReport();
return File(data, 
    \"applica         


        
2条回答
  •  -上瘾入骨i
    2021-02-14 19:57

    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.

提交回复
热议问题