asp.net-mvc - ASP.NET MVC 3 文件下载 : Not Working in IE8

标签 asp.net-mvc internet-explorer-8 download fileresult

我的下载内容只是从本地文件系统提供静态 zip 文件,该文件适用于 Chrome 和 Firefox,但不适用于 IE8。

该网站正在使用 SSL 在本地主机上运行,​​但我在 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));
}

最佳答案

这就是最终对我有用的方法。就我而言,OnActionExecuted 上有一个全局 ActionFilter 将缓存控制设置为“无缓存”。

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";
    }
}

关于asp.net-mvc - ASP.NET MVC 3 文件下载 : Not Working in IE8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16846054/

相关文章:

asp.net-mvc - MVC3 (Razor) 将模型数据从 View 传递到 Controller

ASP.NET MVC 5 加载时间非常慢

asp.net-mvc - ASP.NET MVC 4 中的用户控件等效项

javascript - IE8 上的 jQuery,错误 : Object doesn't support this property or method

javascript - Angular 无法在 IE8 文档模式 7 下工作

javascript - 如何下载通过发布生成的 php 文件,同时避免页面位置被更改?

html - 如何创建适用于所有浏览器的下载链接

jsf - 在 p :fileDownload and hide status when it is finished 开始时显示状态

asp.net-mvc - 如何将editmodel/postmodel突变为域模型

javascript - 当我在 JavaScript 文件中遇到断点时,下拉菜单停留在屏幕上。为什么?