ASP.NET MVC 3 File download: Not Working in IE8

≯℡__Kan透↙ 提交于 2019-12-24 00:17:34

问题


I have the Download that simply serves a static zip file from the local file system that works in Chrome and Firefox, but not in IE8.

The website is running on localhost with SSL, but I am getting the following error message in IE.

Unable to download Download/ from localhost.

Unable to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.

public ActionResult Download(long batchID)
{
    var batchFilePath = string.Format(BatchOrderReportsFolder + "\\Batch-{0}\\Batch-{0}.zip", batchID);
    if (!System.IO.File.Exists(batchFilePath)) {
        return RedirectToAction("Index", "Error");
    }

    return File(batchFilePath, "application/zip", Path.GetFileName(batchFilePath));
}

回答1:


Here's what ultimately worked for me. In my case, there was a global ActionFilter on OnActionExecuted that was setting cache-control to "no-cache".

protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
    base.OnActionExecuted(filterContext);
     var browserInfo = Request.Browser.Browser;
    if (filterContext.Result is FileResult) {
        filterContext.HttpContext.Response.CacheControl = browserInfo == "IE" ? "private" : "no-cache";
    }
}



回答2:


The information in the following question should help you...

Struts application - unable to download file through https on IE



来源:https://stackoverflow.com/questions/16846054/asp-net-mvc-3-file-download-not-working-in-ie8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!