2

我的下载只是从本地文件系统中提供静态 zip 文件,该文件在 Chrome 和 Firefox 中有效,但在 IE8 中无效。

该网站使用 SSL 在 localhost 上运行,但我在 IE 中收到以下错误消息。

无法从 localhost 下载 Download/。

无法打开此 Internet 站点。请求的站点不可用或找不到。请稍后再试。

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));
}
4

2 回答 2

2

这就是最终对我有用的方法。就我而言, 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";
    }
}
于 2013-05-30T22:35:08.867 回答
1

以下问题中的信息应该可以帮助您...

Struts 应用程序 - 无法在 IE 上通过 https 下载文件

于 2013-05-30T22:01:51.117 回答