javascript – 异常:“远程主机关闭了连接.错误代码是0x80070057“
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 异常:“远程主机关闭了连接.错误代码是0x80070057“,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1807字,纯文字阅读大概需要3分钟。
内容图文
![javascript – 异常:“远程主机关闭了连接.错误代码是0x80070057“](/upload/InfoBanner/zyjiaocheng/733/a3ac00923e8e400ea60203ddde5c187d.jpg)
我得到了这个例外.
我遵循了给出的建议
What does this error mean? The remote host closed the connection. The error code is 0x80070057
不过,我得到了同样的错误.
我正在使用Response.WriteFile()将文件从服务器传输到客户端浏览器.
在视图中:
$("#btnExport").on("click", function (e) {
window.location = '@Url.Action("ExportToExcel", "Report")';
e.preventDefault();
});
在控制器中:
[HttpGet]
public RedirectResult ExportToExcel()
{
Download(ExportFilePath);
return new RedirectResult(ExportFilePath);
}
public void Download(ExportFilePath)
{
HttpContext context = System.Web.HttpContext.Current;
FileInfo file = new FileInfo(ExportFilePath);
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();
context.Response.AppendHeader("Content-Disposition", "attachment; filename =" + ExportFileName);
context.Response.AppendHeader("Content-Length", file.Length.ToString());
context.Response.ContentType = "application/excel";
context.Response.WriteFile(file.FullName);
context.Response.Flush();
context.Response.Close();
context.Response.End();
}
解决方法:
我遇到了同样的问题,你应该尝试删除下面的代码行
context.Response.WriteFile(file.FullName);
context.Response.Flush();
context.Response.Close();
context.Response.End();
添加Bellow线
context.Response.TransmitFile(strFileName);
解决方案2:
FileStream myFileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
long FileSize = myFileStream.Length;
byte[] Buffer = new byte[(int)FileSize];
myFileStream.Read(Buffer, 0, (int)FileSize);
myFileStream.Close();
myFileStream.Dispose();
Response.ContentType = "image/jpeg";
Response.AddHeader("Content-Type", "image/jpeg");
Response.AddHeader("Content-Disposition", "attachment;filename=FILENAME.jpg");
Response.BinaryWrite(Buffer);
Response.End();
如果以上解决方案对您不起作用,请告诉我.
内容总结
以上是互联网集市为您收集整理的javascript – 异常:“远程主机关闭了连接.错误代码是0x80070057“全部内容,希望文章能够帮你解决javascript – 异常:“远程主机关闭了连接.错误代码是0x80070057“所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。