我正在使用ASP.NET MVC 5,我在从Safari下载文件时遇到错误,它在FireFox / Chrome上正常运行。
在我的网站上我试图下载xls文件,显示错误(来自Safari)
[错误]无法加载资源:帧加载中断
这是我的代码段
var memStream = new MemoryStream(encoding.GetBytes(model.ExportGenericHtml(true)));
HttpResponseMessage fullResponse = >Request.CreateResponse(HttpStatusCode.OK);
fullResponse.Content = new StreamContent(memStream);
fullResponse.Content.Headers.ContentType = _XlmediaType;
// Response.AddHeader("Content-Length", data.Length.ToString());
fullResponse.Content.Headers.Add("Content-Length", memStream.Length.ToString());
string fileName = "transactions.xls";
fullResponse.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("fileName") { FileName = fileName };
fullResponse.Content.Headers.Add("x-filename", fileName);
return fullResponse;
有什么方法可以解决这个错误吗?
答案 0 :(得分:0)
检查这些参数:
来自Failed to load resource: Frame load interrupted - Agian
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-type: application/x-unknown"); // I always use this
header("Content-Disposition: attachment; filename='theFilename.ext'");
header("Content-Transfer-Encoding: binary");
header("Content-Length: 177998"); // you might want to set this
显然,上述答案中的内容类型并不符合您的需求,但应验证其他参数。