ASP.NET MVC 3文件下载:在IE8不工作 [英] ASP.NET MVC 3 File download: Not Working in IE8
问题描述
我有一个简单的供应以在Chrome和Firefox的作品本地文件系统的静态zip文件下载,但不是在IE8。
该网站上使用SSL本地主机上运行,但我在IE中得到以下错误消息。
无法下载下载/从本地主机。
无法打开此Internet站点。该请求的站点
不可用或不能被发现。请稍后再试。
块引用>公众的ActionResult下载(长batchID)
{
VAR batchFilePath =的String.Format(BatchOrderReportsFolder +\\\\分批{0} \\\\分批{0}的.zip,batchID);
如果(!System.IO.File.Exists(batchFilePath)){
返回RedirectToAction(指数,错误);
} 返回文件(batchFilePath,应用程序/压缩,Path.GetFileName(batchFilePath));
}
解决方案下面是最终为我工作。就我而言,有上OnActionExecuted一个全球性的ActionFilter被设置缓存控制为无缓存。
保护覆盖无效OnActionExecuted(ActionExecutedContext filterContext)
{
base.OnActionExecuted(filterContext);
VAR browserInfo = Request.Browser.Browser;
如果(filterContext.Result是FileResult){
filterContext.HttpContext.Response.CacheControl = browserInfo ==IE? 私:无缓存;
}
}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)); }
解决方案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"; } }
这篇关于ASP.NET MVC 3文件下载:在IE8不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!